home *** CD-ROM | disk | FTP | other *** search
/ Risc World 7 / Risc World 7.iso / Software / Issue6 / SDL.ZIP / !gcc / docs / diff < prev    next >
Text File  |  2006-09-17  |  341KB  |  5,560 lines

  1. <html lang="en">
  2. <head>
  3. <title>Comparing and Merging Files</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="Comparing and Merging Files">
  6. <meta name="generator" content="makeinfo 4.8">
  7. <link title="Top" rel="top" href="#Top">
  8. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  9. <!--
  10. This manual is for GNU Diffutils
  11. (version 2.8.1, 5 April 2002),
  12. and documents the GNU `diff', `diff3',
  13. `sdiff', and `cmp' commands for showing the
  14. differences between files and the GNU `patch' command for
  15. using their output to update files.
  16.  
  17. Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free
  18. Software Foundation, Inc.
  19.  
  20.      Permission is granted to copy, distribute and/or modify this
  21.      document under the terms of the GNU Free Documentation License,
  22.      Version 1.1 or any later version published by the Free Software
  23.      Foundation; with no Invariant Sections, with the Front-Cover texts
  24.      being "A GNU Manual," and with the Back-Cover Texts as in (a)
  25.      below.  A copy of the license is included in the section entitled
  26.      "GNU Free Documentation License."
  27.  
  28.      (a) The FSF's Back-Cover Text is: "You have freedom to copy and
  29.      modify this GNU Manual, like GNU software.  Copies published by
  30.      the Free Software Foundation raise funds for GNU development."
  31.    -->
  32. <meta http-equiv="Content-Style-Type" content="text/css">
  33. <style type="text/css"><!--
  34.   pre.display { font-family:inherit }
  35.   pre.format  { font-family:inherit }
  36.   pre.smalldisplay { font-family:inherit; font-size:smaller }
  37.   pre.smallformat  { font-family:inherit; font-size:smaller }
  38.   pre.smallexample { font-size:smaller }
  39.   pre.smalllisp    { font-size:smaller }
  40.   span.sc    { font-variant:small-caps }
  41.   span.roman { font-family:serif; font-weight:normal; } 
  42.   span.sansserif { font-family:sans-serif; font-weight:normal; } 
  43. --></style>
  44. </head>
  45. <body>
  46. <h1 class="settitle">Comparing and Merging Files</h1>
  47.    <div class="shortcontents">
  48. <h2>Short Contents</h2>
  49. <ul>
  50. <li><a href="#toc_Top">Comparing and Merging Files</a></li>
  51. <li><a href="#toc_Overview">Overview</a></li>
  52. <li><a href="#toc_Comparison">1 What Comparison Means</a></li>
  53. <li><a href="#toc_Output-Formats">2 <samp><span class="command">diff</span></samp> Output Formats</a></li>
  54. <li><a href="#toc_Incomplete-Lines">3 Incomplete Lines</a></li>
  55. <li><a href="#toc_Comparing-Directories">4 Comparing Directories</a></li>
  56. <li><a href="#toc_Adjusting-Output">5 Making <samp><span class="command">diff</span></samp> Output Prettier</a></li>
  57. <li><a href="#toc_diff-Performance">6 <samp><span class="command">diff</span></samp> Performance Tradeoffs</a></li>
  58. <li><a href="#toc_Comparing-Three-Files">7 Comparing Three Files</a></li>
  59. <li><a href="#toc_diff3-Merging">8 Merging From a Common Ancestor</a></li>
  60. <li><a href="#toc_Interactive-Merging">9 Interactive Merging with <samp><span class="command">sdiff</span></samp></a></li>
  61. <li><a href="#toc_Merging-with-patch">10 Merging with <samp><span class="command">patch</span></samp></a></li>
  62. <li><a href="#toc_Making-Patches">11 Tips for Making and Using Patches</a></li>
  63. <li><a href="#toc_Invoking-cmp">12 Invoking <samp><span class="command">cmp</span></samp></a></li>
  64. <li><a href="#toc_Invoking-diff">13 Invoking <samp><span class="command">diff</span></samp></a></li>
  65. <li><a href="#toc_Invoking-diff3">14 Invoking <samp><span class="command">diff3</span></samp></a></li>
  66. <li><a href="#toc_Invoking-patch">15 Invoking <samp><span class="command">patch</span></samp></a></li>
  67. <li><a href="#toc_Invoking-sdiff">16 Invoking <samp><span class="command">sdiff</span></samp></a></li>
  68. <li><a href="#toc_Standards-conformance">17 Standards conformance</a></li>
  69. <li><a href="#toc_Projects">18 Future Projects</a></li>
  70. <li><a href="#toc_Copying-This-Manual">Appendix A Copying This Manual</a></li>
  71. <li><a href="#toc_Index">Appendix B Index</a></li>
  72. </ul>
  73. </div>
  74.  
  75.  
  76.  
  77.    <div class="contents">
  78. <h2>Table of Contents</h2>
  79. <ul>
  80. <li><a name="toc_Top" href="#Top">Comparing and Merging Files</a>
  81. <li><a name="toc_Overview" href="#Overview">Overview</a>
  82. <li><a name="toc_Comparison" href="#Comparison">1 What Comparison Means</a>
  83. <ul>
  84. <li><a href="#Hunks">1.1 Hunks</a>
  85. <li><a href="#White-Space">1.2 Suppressing Differences in Blank and Tab Spacing</a>
  86. <li><a href="#Blank-Lines">1.3 Suppressing Differences in Blank Lines</a>
  87. <li><a href="#Case-Folding">1.4 Suppressing Case Differences</a>
  88. <li><a href="#Specified-Folding">1.5 Suppressing Lines Matching a Regular Expression</a>
  89. <li><a href="#Brief">1.6 Summarizing Which Files Differ</a>
  90. <li><a href="#Binary">1.7 Binary Files and Forcing Text Comparisons</a>
  91. </li></ul>
  92. <li><a name="toc_Output-Formats" href="#Output-Formats">2 <samp><span class="command">diff</span></samp> Output Formats</a>
  93. <ul>
  94. <li><a href="#Sample-diff-Input">2.1 Two Sample Input Files</a>
  95. <li><a href="#Normal">2.2 Showing Differences Without Context</a>
  96. <ul>
  97. <li><a href="#Detailed-Normal">2.2.1 Detailed Description of Normal Format</a>
  98. <li><a href="#Example-Normal">2.2.2 An Example of Normal Format</a>
  99. </li></ul>
  100. <li><a href="#Context">2.3 Showing Differences in Their Context</a>
  101. <ul>
  102. <li><a href="#Context-Format">2.3.1 Context Format</a>
  103. <ul>
  104. <li><a href="#Detailed-Context">2.3.1.1 Detailed Description of Context Format</a>
  105. <li><a href="#Example-Context">2.3.1.2 An Example of Context Format</a>
  106. <li><a href="#Less-Context">2.3.1.3 An Example of Context Format with Less Context</a>
  107. </li></ul>
  108. <li><a href="#Unified-Format">2.3.2 Unified Format</a>
  109. <ul>
  110. <li><a href="#Detailed-Unified">2.3.2.1 Detailed Description of Unified Format</a>
  111. <li><a href="#Example-Unified">2.3.2.2 An Example of Unified Format</a>
  112. </li></ul>
  113. <li><a href="#Sections">2.3.3 Showing Which Sections Differences Are in</a>
  114. <ul>
  115. <li><a href="#Specified-Headings">2.3.3.1 Showing Lines That Match Regular Expressions</a>
  116. <li><a href="#C-Function-Headings">2.3.3.2 Showing C Function Headings</a>
  117. </li></ul>
  118. <li><a href="#Alternate-Names">2.3.4 Showing Alternate File Names</a>
  119. </li></ul>
  120. <li><a href="#Side-by-Side">2.4 Showing Differences Side by Side</a>
  121. <ul>
  122. <li><a href="#Side-by-Side-Format">2.4.1 Controlling Side by Side Format</a>
  123. <li><a href="#Example-Side-by-Side">2.4.2 An Example of Side by Side Format</a>
  124. </li></ul>
  125. <li><a href="#Scripts">2.5 Making Edit Scripts</a>
  126. <ul>
  127. <li><a href="#ed-Scripts">2.5.1 <samp><span class="command">ed</span></samp> Scripts</a>
  128. <ul>
  129. <li><a href="#Detailed-ed">2.5.1.1 Detailed Description of <samp><span class="command">ed</span></samp> Format</a>
  130. <li><a href="#Example-ed">2.5.1.2 Example <samp><span class="command">ed</span></samp> Script</a>
  131. </li></ul>
  132. <li><a href="#Forward-ed">2.5.2 Forward <samp><span class="command">ed</span></samp> Scripts</a>
  133. <li><a href="#RCS">2.5.3 <span class="sc">rcs</span> Scripts</a>
  134. </li></ul>
  135. <li><a href="#If_002dthen_002delse">2.6 Merging Files with If-then-else</a>
  136. <ul>
  137. <li><a href="#Line-Group-Formats">2.6.1 Line Group Formats</a>
  138. <li><a href="#Line-Formats">2.6.2 Line Formats</a>
  139. <li><a href="#Detailed-If_002dthen_002delse">2.6.3 Detailed Description of If-then-else Format</a>
  140. <li><a href="#Example-If_002dthen_002delse">2.6.4 An Example of If-then-else Format</a>
  141. </li></ul>
  142. </li></ul>
  143. <li><a name="toc_Incomplete-Lines" href="#Incomplete-Lines">3 Incomplete Lines</a>
  144. <li><a name="toc_Comparing-Directories" href="#Comparing-Directories">4 Comparing Directories</a>
  145. <li><a name="toc_Adjusting-Output" href="#Adjusting-Output">5 Making <samp><span class="command">diff</span></samp> Output Prettier</a>
  146. <ul>
  147. <li><a href="#Tabs">5.1 Preserving Tab Stop Alignment</a>
  148. <li><a href="#Pagination">5.2 Paginating <samp><span class="command">diff</span></samp> Output</a>
  149. </li></ul>
  150. <li><a name="toc_diff-Performance" href="#diff-Performance">6 <samp><span class="command">diff</span></samp> Performance Tradeoffs</a>
  151. <li><a name="toc_Comparing-Three-Files" href="#Comparing-Three-Files">7 Comparing Three Files</a>
  152. <ul>
  153. <li><a href="#Sample-diff3-Input">7.1 A Third Sample Input File</a>
  154. <li><a href="#Detailed-diff3-Normal">7.2 Detailed Description of <samp><span class="command">diff3</span></samp> Normal Format</a>
  155. <li><a href="#diff3-Hunks">7.3 <samp><span class="command">diff3</span></samp> Hunks</a>
  156. <li><a href="#Example-diff3-Normal">7.4 An Example of <samp><span class="command">diff3</span></samp> Normal Format</a>
  157. </li></ul>
  158. <li><a name="toc_diff3-Merging" href="#diff3-Merging">8 Merging From a Common Ancestor</a>
  159. <ul>
  160. <li><a href="#Which-Changes">8.1 Selecting Which Changes to Incorporate</a>
  161. <li><a href="#Marking-Conflicts">8.2 Marking Conflicts</a>
  162. <li><a href="#Bypassing-ed">8.3 Generating the Merged Output Directly</a>
  163. <li><a href="#Merging-Incomplete-Lines">8.4 How <samp><span class="command">diff3</span></samp> Merges Incomplete Lines</a>
  164. <li><a href="#Saving-the-Changed-File">8.5 Saving the Changed File</a>
  165. </li></ul>
  166. <li><a name="toc_Interactive-Merging" href="#Interactive-Merging">9 Interactive Merging with <samp><span class="command">sdiff</span></samp></a>
  167. <ul>
  168. <li><a href="#sdiff-Option-Summary">9.1 Specifying <samp><span class="command">diff</span></samp> Options to <samp><span class="command">sdiff</span></samp></a>
  169. <li><a href="#Merge-Commands">9.2 Merge Commands</a>
  170. </li></ul>
  171. <li><a name="toc_Merging-with-patch" href="#Merging-with-patch">10 Merging with <samp><span class="command">patch</span></samp></a>
  172. <ul>
  173. <li><a href="#patch-Input">10.1 Selecting the <samp><span class="command">patch</span></samp> Input Format</a>
  174. <li><a href="#Revision-Control">10.2 Revision Control</a>
  175. <li><a href="#Imperfect">10.3 Applying Imperfect Patches</a>
  176. <ul>
  177. <li><a href="#Changed-White-Space">10.3.1 Applying Patches with Changed White Space</a>
  178. <li><a href="#Reversed-Patches">10.3.2 Applying Reversed Patches</a>
  179. <li><a href="#Inexact">10.3.3 Helping <samp><span class="command">patch</span></samp> Find Inexact Matches</a>
  180. <li><a href="#Dry-Runs">10.3.4 Predicting what <samp><span class="command">patch</span></samp> will do</a>
  181. </li></ul>
  182. <li><a href="#Creating-and-Removing">10.4 Creating and Removing Files</a>
  183. <li><a href="#Patching-Time-Stamps">10.5 Updating Time Stamps on Patched Files</a>
  184. <li><a href="#Multiple-Patches">10.6 Multiple Patches in a File</a>
  185. <li><a href="#patch-Directories">10.7 Applying Patches in Other Directories</a>
  186. <li><a href="#Backups">10.8 Backup Files</a>
  187. <li><a href="#Backup-Names">10.9 Backup File Names</a>
  188. <li><a href="#Reject-Names">10.10 Reject File Names</a>
  189. <li><a href="#patch-Messages">10.11 Messages and Questions from <samp><span class="command">patch</span></samp></a>
  190. <ul>
  191. <li><a href="#More-or-Fewer-Messages">10.11.1 Controlling the Verbosity of <samp><span class="command">patch</span></samp></a>
  192. <li><a href="#patch-and-Keyboard-Input">10.11.2 Inhibiting Keyboard Input</a>
  193. <li><a href="#patch-Quoting-Style">10.11.3 <samp><span class="command">patch</span></samp> Quoting Style</a>
  194. </li></ul>
  195. <li><a href="#patch-and-POSIX">10.12 <samp><span class="command">patch</span></samp> and the <span class="sc">posix</span> Standard</a>
  196. <li><a href="#patch-and-Tradition">10.13 <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> and Traditional <samp><span class="command">patch</span></samp></a>
  197. </li></ul>
  198. <li><a name="toc_Making-Patches" href="#Making-Patches">11 Tips for Making and Using Patches</a>
  199. <ul>
  200. <li><a href="#Tips-for-Patch-Producers">11.1 Tips for Patch Producers</a>
  201. <li><a href="#Tips-for-Patch-Consumers">11.2 Tips for Patch Consumers</a>
  202. <li><a href="#Avoiding-Common-Mistakes">11.3 Avoiding Common Mistakes</a>
  203. <li><a href="#Generating-Smaller-Patches">11.4 Generating Smaller Patches</a>
  204. </li></ul>
  205. <li><a name="toc_Invoking-cmp" href="#Invoking-cmp">12 Invoking <samp><span class="command">cmp</span></samp></a>
  206. <ul>
  207. <li><a href="#cmp-Options">12.1 Options to <samp><span class="command">cmp</span></samp></a>
  208. </li></ul>
  209. <li><a name="toc_Invoking-diff" href="#Invoking-diff">13 Invoking <samp><span class="command">diff</span></samp></a>
  210. <ul>
  211. <li><a href="#diff-Options">13.1 Options to <samp><span class="command">diff</span></samp></a>
  212. </li></ul>
  213. <li><a name="toc_Invoking-diff3" href="#Invoking-diff3">14 Invoking <samp><span class="command">diff3</span></samp></a>
  214. <ul>
  215. <li><a href="#diff3-Options">14.1 Options to <samp><span class="command">diff3</span></samp></a>
  216. </li></ul>
  217. <li><a name="toc_Invoking-patch" href="#Invoking-patch">15 Invoking <samp><span class="command">patch</span></samp></a>
  218. <ul>
  219. <li><a href="#patch-Options">15.1 Options to <samp><span class="command">patch</span></samp></a>
  220. </li></ul>
  221. <li><a name="toc_Invoking-sdiff" href="#Invoking-sdiff">16 Invoking <samp><span class="command">sdiff</span></samp></a>
  222. <ul>
  223. <li><a href="#sdiff-Options">16.1 Options to <samp><span class="command">sdiff</span></samp></a>
  224. </li></ul>
  225. <li><a name="toc_Standards-conformance" href="#Standards-conformance">17 Standards conformance</a>
  226. <li><a name="toc_Projects" href="#Projects">18 Future Projects</a>
  227. <ul>
  228. <li><a href="#Shortcomings">18.1 Suggested Projects for Improving <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></a>
  229. <ul>
  230. <li><a href="#Internationalization">18.1.1 Handling Multibyte and Varying-Width Characters</a>
  231. <li><a href="#Changing-Structure">18.1.2 Handling Changes to the Directory Structure</a>
  232. <li><a href="#Special-Files">18.1.3 Files that are Neither Directories Nor Regular Files</a>
  233. <li><a href="#Unusual-File-Names">18.1.4 File Names that Contain Unusual Characters</a>
  234. <li><a href="#Time-Stamp-Order">18.1.5 Outputting Diffs in Time Stamp Order</a>
  235. <li><a href="#Ignoring-Changes">18.1.6 Ignoring Certain Changes</a>
  236. <li><a href="#Speedups">18.1.7 Improving Performance</a>
  237. </li></ul>
  238. <li><a href="#Bugs">18.2 Reporting Bugs</a>
  239. </li></ul>
  240. <li><a name="toc_Copying-This-Manual" href="#Copying-This-Manual">Appendix A Copying This Manual</a>
  241. <ul>
  242. <li><a href="#GNU-Free-Documentation-License">A.1 GNU Free Documentation License</a>
  243. <ul>
  244. <li><a href="#GNU-Free-Documentation-License">A.1.1 ADDENDUM: How to use this License for your documents</a>
  245. </li></ul>
  246. </li></ul>
  247. <li><a name="toc_Index" href="#Index">Appendix B Index</a>
  248. </li></ul>
  249. </div>
  250.  
  251. <div class="node">
  252. <p><hr>
  253. <a name="Top"></a>
  254. Next: <a rel="next" accesskey="n" href="#Overview">Overview</a>,
  255. Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
  256.  
  257. </div>
  258.  
  259. <h2 class="unnumbered">Comparing and Merging Files</h2>
  260.  
  261. <p>This manual is for GNU Diffutils
  262. (version 2.8.1, 5 April 2002),
  263. and documents the <span class="sc">gnu</span> <samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp>,
  264. <samp><span class="command">sdiff</span></samp>, and <samp><span class="command">cmp</span></samp> commands for showing the
  265. differences between files and the <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> command for
  266. using their output to update files.
  267.  
  268.    <p>Copyright © 1992, 1993, 1994, 1998, 2001, 2002 Free
  269. Software Foundation, Inc.
  270.  
  271.    <blockquote>
  272. Permission is granted to copy, distribute and/or modify this document
  273. under the terms of the GNU Free Documentation License, Version 1.1 or
  274. any later version published by the Free Software Foundation; with no
  275. Invariant Sections, with the Front-Cover texts being “A GNU Manual,”
  276. and with the Back-Cover Texts as in (a) below.  A copy of the
  277. license is included in the section entitled “GNU Free Documentation
  278. License.”
  279.  
  280.         <p>(a) The FSF's Back-Cover Text is: “You have freedom to copy and modify
  281. this GNU Manual, like GNU software.  Copies published by the Free
  282. Software Foundation raise funds for GNU development.”
  283. </blockquote>
  284.  
  285. <ul class="menu">
  286. <li><a accesskey="1" href="#Overview">Overview</a>:               Preliminary information. 
  287. <li><a accesskey="2" href="#Comparison">Comparison</a>:             What file comparison means.
  288.  
  289. <li><a accesskey="3" href="#Output-Formats">Output Formats</a>:         Formats for two-way difference reports. 
  290. <li><a accesskey="4" href="#Incomplete-Lines">Incomplete Lines</a>:       Lines that lack trailing newlines. 
  291. <li><a accesskey="5" href="#Comparing-Directories">Comparing Directories</a>:  Comparing files and directories. 
  292. <li><a accesskey="6" href="#Adjusting-Output">Adjusting Output</a>:       Making <samp><span class="command">diff</span></samp> output prettier. 
  293. <li><a accesskey="7" href="#diff-Performance">diff Performance</a>:       Making <samp><span class="command">diff</span></samp> smarter or faster.
  294.  
  295. <li><a accesskey="8" href="#Comparing-Three-Files">Comparing Three Files</a>:  Formats for three-way difference reports. 
  296. <li><a accesskey="9" href="#diff3-Merging">diff3 Merging</a>:          Merging from a common ancestor.
  297.  
  298. <li><a href="#Interactive-Merging">Interactive Merging</a>:    Interactive merging with <samp><span class="command">sdiff</span></samp>.
  299.  
  300. <li><a href="#Merging-with-patch">Merging with patch</a>:     Using <samp><span class="command">patch</span></samp> to change old files into new ones. 
  301. <li><a href="#Making-Patches">Making Patches</a>:         Tips for making and using patch distributions.
  302.  
  303. <li><a href="#Invoking-cmp">Invoking cmp</a>:           Compare two files byte by byte. 
  304. <li><a href="#Invoking-diff">Invoking diff</a>:          Compare two files line by line. 
  305. <li><a href="#Invoking-diff3">Invoking diff3</a>:         Compare three files line by line. 
  306. <li><a href="#Invoking-patch">Invoking patch</a>:         Apply a diff file to an original. 
  307. <li><a href="#Invoking-sdiff">Invoking sdiff</a>:         Side-by-side merge of file differences.
  308.  
  309. <li><a href="#Standards-conformance">Standards conformance</a>:  Conformance to the <span class="sc">posix</span> standard. 
  310. <li><a href="#Projects">Projects</a>:               If you've found a bug or other shortcoming.
  311.  
  312. <li><a href="#Copying-This-Manual">Copying This Manual</a>:    How to make copies of this manual. 
  313. <li><a href="#Index">Index</a>:                  Index. 
  314. </ul>
  315.  
  316. <div class="node">
  317. <p><hr>
  318. <a name="Overview"></a>
  319. Next: <a rel="next" accesskey="n" href="#Comparison">Comparison</a>,
  320. Previous: <a rel="previous" accesskey="p" href="#Top">Top</a>,
  321. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  322.  
  323. </div>
  324.  
  325. <h2 class="unnumbered">Overview</h2>
  326.  
  327. <p><a name="index-overview-of-_0040command_007bdiff_007d-and-_0040command_007bpatch_007d-1"></a>
  328. Computer users often find occasion to ask how two files differ.  Perhaps
  329. one file is a newer version of the other file.  Or maybe the two files
  330. started out as identical copies but were changed by different people.
  331.  
  332.    <p>You can use the <samp><span class="command">diff</span></samp> command to show differences between two
  333. files, or each corresponding file in two directories.  <samp><span class="command">diff</span></samp>
  334. outputs differences between files line by line in any of several
  335. formats, selectable by command line options.  This set of differences is
  336. often called a <dfn>diff</dfn> or <dfn>patch</dfn>.  For files that are identical,
  337. <samp><span class="command">diff</span></samp> normally produces no output; for binary (non-text) files,
  338. <samp><span class="command">diff</span></samp> normally reports only that they are different.
  339.  
  340.    <p>You can use the <samp><span class="command">cmp</span></samp> command to show the byte and line numbers
  341. where two files differ.  <samp><span class="command">cmp</span></samp> can also show all the bytes
  342. that differ between the two files, side by side.  A way to compare
  343. two files character by character is the Emacs command <kbd>M-x
  344. compare-windows</kbd>.  See <a href="emacs.html#Other-Window">Other Window</a>, for more information on that command.
  345.  
  346.    <p>You can use the <samp><span class="command">diff3</span></samp> command to show differences among three
  347. files.  When two people have made independent changes to a common
  348. original, <samp><span class="command">diff3</span></samp> can report the differences between the original
  349. and the two changed versions, and can produce a merged file that
  350. contains both persons' changes together with warnings about conflicts.
  351.  
  352.    <p>You can use the <samp><span class="command">sdiff</span></samp> command to merge two files interactively.
  353.  
  354.    <p>You can use the set of differences produced by <samp><span class="command">diff</span></samp> to distribute
  355. updates to text files (such as program source code) to other people. 
  356. This method is especially useful when the differences are small compared
  357. to the complete files.  Given <samp><span class="command">diff</span></samp> output, you can use the
  358. <samp><span class="command">patch</span></samp> program to update, or <dfn>patch</dfn>, a copy of the file.  If you
  359. think of <samp><span class="command">diff</span></samp> as subtracting one file from another to produce
  360. their difference, you can think of <samp><span class="command">patch</span></samp> as adding the difference
  361. to one file to reproduce the other.
  362.  
  363.    <p>This manual first concentrates on making diffs, and later shows how to
  364. use diffs to update files.
  365.  
  366.    <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> was written by Paul Eggert, Mike Haertel,
  367. David Hayes, Richard Stallman, and Len Tower.  Wayne Davison designed and
  368. implemented the unified output format.  The basic algorithm is described
  369. in “An O(ND) Difference Algorithm and its Variations”, Eugene W. Myers,
  370. <cite>Algorithmica</cite> Vol. 1 No. 2, 1986, pp. 251–266; and in “A File
  371. Comparison Program”, Webb Miller and Eugene W. Myers,
  372. <cite>Software—Practice and Experience</cite> Vol. 15 No. 11, 1985,
  373. pp. 1025–1040. 
  374. <!-- From: "Gene Myers" <gene@cs.arizona.edu> -->
  375. <!-- They are about the same basic algorithm; the Algorithmica -->
  376. <!-- paper gives a rigorous treatment and the sub-algorithm for -->
  377. <!-- delivering scripts and should be the primary reference, but -->
  378. <!-- both should be mentioned. -->
  379. The algorithm was independently discovered as described in
  380. “Algorithms for Approximate String Matching”,
  381. E. Ukkonen, <cite>Information and Control</cite> Vol. 64, 1985, pp. 100–118. 
  382. <!-- From: "Gene Myers" <gene@cs.arizona.edu> -->
  383. <!-- Date: Wed, 29 Sep 1993 08:27:55 MST -->
  384. <!-- Ukkonen should be given credit for also discovering the algorithm used -->
  385. <!-- in GNU diff. -->
  386.  
  387.    <p><span class="sc">gnu</span> <samp><span class="command">diff3</span></samp> was written by Randy Smith.  <span class="sc">gnu</span>
  388. <samp><span class="command">sdiff</span></samp> was written by Thomas Lord.  <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>
  389. was written by Torbjorn Granlund and David MacKenzie.
  390.  
  391.    <p><samp><span class="command">patch</span></samp> was written mainly by Larry Wall and Paul Eggert;
  392. several <span class="sc">gnu</span> enhancements were contributed by Wayne Davison and
  393. David MacKenzie.  Parts of this manual are adapted from a manual page
  394. written by Larry Wall, with his permission.
  395.  
  396. <div class="node">
  397. <p><hr>
  398. <a name="Comparison"></a>
  399. Next: <a rel="next" accesskey="n" href="#Output-Formats">Output Formats</a>,
  400. Previous: <a rel="previous" accesskey="p" href="#Overview">Overview</a>,
  401. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  402.  
  403. </div>
  404.  
  405. <h2 class="chapter">1 What Comparison Means</h2>
  406.  
  407. <p><a name="index-introduction-2"></a>
  408. There are several ways to think about the differences between two files. 
  409. One way to think of the differences is as a series of lines that were
  410. deleted from, inserted in, or changed in one file to produce the other
  411. file.  <samp><span class="command">diff</span></samp> compares two files line by line, finds groups of
  412. lines that differ, and reports each group of differing lines.  It can
  413. report the differing lines in several formats, which have different
  414. purposes.
  415.  
  416.    <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can show whether files are different without detailing
  417. the differences.  It also provides ways to suppress certain kinds of
  418. differences that are not important to you.  Most commonly, such
  419. differences are changes in the amount of white space between words or
  420. lines.  <samp><span class="command">diff</span></samp> also provides ways to suppress differences in
  421. alphabetic case or in lines that match a regular expression that you
  422. provide.  These options can accumulate; for example, you can ignore
  423. changes in both white space and alphabetic case.
  424.  
  425.    <p>Another way to think of the differences between two files is as a
  426. sequence of pairs of bytes that can be either identical or
  427. different.  <samp><span class="command">cmp</span></samp> reports the differences between two files
  428. byte by byte, instead of line by line.  As a result, it is often
  429. more useful than <samp><span class="command">diff</span></samp> for comparing binary files.  For text
  430. files, <samp><span class="command">cmp</span></samp> is useful mainly when you want to know only whether
  431. two files are identical, or whether one file is a prefix of the other.
  432.  
  433.    <p>To illustrate the effect that considering changes byte by byte
  434. can have compared with considering them line by line, think of what
  435. happens if a single newline character is added to the beginning of a
  436. file.  If that file is then compared with an otherwise identical file
  437. that lacks the newline at the beginning, <samp><span class="command">diff</span></samp> will report that a
  438. blank line has been added to the file, while <samp><span class="command">cmp</span></samp> will report that
  439. almost every byte of the two files differs.
  440.  
  441.    <p><samp><span class="command">diff3</span></samp> normally compares three input files line by line, finds
  442. groups of lines that differ, and reports each group of differing lines. 
  443. Its output is designed to make it easy to inspect two different sets of
  444. changes to the same file.
  445.  
  446. <ul class="menu">
  447. <li><a accesskey="1" href="#Hunks">Hunks</a>:              Groups of differing lines. 
  448. <li><a accesskey="2" href="#White-Space">White Space</a>:        Suppressing differences in white space. 
  449. <li><a accesskey="3" href="#Blank-Lines">Blank Lines</a>:        Suppressing differences in blank lines. 
  450. <li><a accesskey="4" href="#Case-Folding">Case Folding</a>:       Suppressing differences in alphabetic case. 
  451. <li><a accesskey="5" href="#Specified-Folding">Specified Folding</a>:  Suppressing differences that match regular expressions. 
  452. <li><a accesskey="6" href="#Brief">Brief</a>:              Summarizing which files are different. 
  453. <li><a accesskey="7" href="#Binary">Binary</a>:             Comparing binary files or forcing text comparisons. 
  454. </ul>
  455.  
  456. <div class="node">
  457. <p><hr>
  458. <a name="Hunks"></a>
  459. Next: <a rel="next" accesskey="n" href="#White-Space">White Space</a>,
  460. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  461.  
  462. </div>
  463.  
  464. <h3 class="section">1.1 Hunks</h3>
  465.  
  466. <p><a name="index-hunks-3"></a>
  467. When comparing two files, <samp><span class="command">diff</span></samp> finds sequences of lines common to
  468. both files, interspersed with groups of differing lines called
  469. <dfn>hunks</dfn>.  Comparing two identical files yields one sequence of
  470. common lines and no hunks, because no lines differ.  Comparing two
  471. entirely different files yields no common lines and one large hunk that
  472. contains all lines of both files.  In general, there are many ways to
  473. match up lines between two given files.  <samp><span class="command">diff</span></samp> tries to minimize
  474. the total hunk size by finding large sequences of common lines
  475. interspersed with small hunks of differing lines.
  476.  
  477.    <p>For example, suppose the file <samp><span class="file">F</span></samp> contains the three lines
  478. `<samp><span class="samp">a</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">c</span></samp>', and the file <samp><span class="file">G</span></samp> contains the same
  479. three lines in reverse order `<samp><span class="samp">c</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">a</span></samp>'.  If
  480. <samp><span class="command">diff</span></samp> finds the line `<samp><span class="samp">c</span></samp>' as common, then the command
  481. `<samp><span class="samp">diff F G</span></samp>' produces this output:
  482.  
  483. <pre class="example">     1,2d0
  484.      < a
  485.      < b
  486.      3a2,3
  487.      > b
  488.      > a
  489. </pre>
  490.    <p class="noindent">But if <samp><span class="command">diff</span></samp> notices the common line `<samp><span class="samp">b</span></samp>' instead, it produces
  491. this output:
  492.  
  493. <pre class="example">     1c1
  494.      < a
  495.      ---
  496.      > c
  497.      3c3
  498.      < c
  499.      ---
  500.      > a
  501. </pre>
  502.    <p class="noindent">It is also possible to find `<samp><span class="samp">a</span></samp>' as the common line.  <samp><span class="command">diff</span></samp>
  503. does not always find an optimal matching between the files; it takes
  504. shortcuts to run faster.  But its output is usually close to the
  505. shortest possible.  You can adjust this tradeoff with the
  506. <samp><span class="option">--minimal</span></samp> option (see <a href="#diff-Performance">diff Performance</a>).
  507.  
  508. <div class="node">
  509. <p><hr>
  510. <a name="White-Space"></a>
  511. Next: <a rel="next" accesskey="n" href="#Blank-Lines">Blank Lines</a>,
  512. Previous: <a rel="previous" accesskey="p" href="#Hunks">Hunks</a>,
  513. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  514.  
  515. </div>
  516.  
  517. <h3 class="section">1.2 Suppressing Differences in Blank and Tab Spacing</h3>
  518.  
  519. <p><a name="index-blank-and-tab-difference-suppression-4"></a><a name="index-tab-and-blank-difference-suppression-5"></a>
  520. The <samp><span class="option">-E</span></samp> and <samp><span class="option">--ignore-tab-expansion</span></samp> options ignore the
  521. distinction between tabs and spaces on input.  A tab is considered to be
  522. equivalent to the number of spaces to the next tab stop.  <samp><span class="command">diff</span></samp>
  523. assumes that tab stops are set every 8 print columns.
  524.  
  525.    <p>The <samp><span class="option">-b</span></samp> and <samp><span class="option">--ignore-space-change</span></samp> options are stronger. 
  526. They ignore white space at line end, and consider all other sequences of
  527. one or more white space characters to be equivalent.  With these
  528. options, <samp><span class="command">diff</span></samp> considers the following two lines to be equivalent,
  529. where `<samp><span class="samp">$</span></samp>' denotes the line end:
  530.  
  531. <pre class="example">     Here lyeth  muche rychnesse  in lytell space.   -- John Heywood$
  532.      Here lyeth muche rychnesse in lytell space. -- John Heywood   $
  533. </pre>
  534.    <p>The <samp><span class="option">-w</span></samp> and <samp><span class="option">--ignore-all-space</span></samp> options are stronger still. 
  535. They ignore difference even if one line has white space where
  536. the other line has none.  <dfn>White space</dfn> characters include
  537. tab, newline, vertical tab, form feed, carriage return, and space;
  538. some locales may define additional characters to be white space. 
  539. With these options, <samp><span class="command">diff</span></samp> considers the
  540. following two lines to be equivalent, where `<samp><span class="samp">$</span></samp>' denotes the line
  541. end and `<samp><span class="samp">^M</span></samp>' denotes a carriage return:
  542.  
  543. <pre class="example">     Here lyeth  muche  rychnesse in lytell space.--  John Heywood$
  544.        He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
  545. </pre>
  546.    <div class="node">
  547. <p><hr>
  548. <a name="Blank-Lines"></a>
  549. Next: <a rel="next" accesskey="n" href="#Case-Folding">Case Folding</a>,
  550. Previous: <a rel="previous" accesskey="p" href="#White-Space">White Space</a>,
  551. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  552.  
  553. </div>
  554.  
  555. <h3 class="section">1.3 Suppressing Differences in Blank Lines</h3>
  556.  
  557. <p><a name="index-blank-line-difference-suppression-6"></a>
  558. The <samp><span class="option">-B</span></samp> and <samp><span class="option">--ignore-blank-lines</span></samp> options ignore insertions
  559. or deletions of blank lines.  These options affect only lines
  560. that are completely empty; they do not affect lines that look empty but
  561. contain space or tab characters.  With these options, for example, a
  562. file containing
  563. <pre class="example">     1.  A point is that which has no part.
  564.      
  565.      2.  A line is breadthless length.
  566.      -- Euclid, The Elements, I
  567. </pre>
  568.    <p class="noindent">is considered identical to a file containing
  569. <pre class="example">     1.  A point is that which has no part.
  570.      2.  A line is breadthless length.
  571.      
  572.      
  573.      -- Euclid, The Elements, I
  574. </pre>
  575.    <div class="node">
  576. <p><hr>
  577. <a name="Case-Folding"></a>
  578. Next: <a rel="next" accesskey="n" href="#Specified-Folding">Specified Folding</a>,
  579. Previous: <a rel="previous" accesskey="p" href="#Blank-Lines">Blank Lines</a>,
  580. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  581.  
  582. </div>
  583.  
  584. <h3 class="section">1.4 Suppressing Case Differences</h3>
  585.  
  586. <p><a name="index-case-difference-suppression-7"></a>
  587. <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can treat lower case letters as equivalent to their
  588. upper case counterparts, so that, for example, it considers `<samp><span class="samp">Funky
  589. Stuff</span></samp>', `<samp><span class="samp">funky STUFF</span></samp>', and `<samp><span class="samp">fUNKy stuFf</span></samp>' to all be the same. 
  590. To request this, use the <samp><span class="option">-i</span></samp> or <samp><span class="option">--ignore-case</span></samp> option.
  591.  
  592. <div class="node">
  593. <p><hr>
  594. <a name="Specified-Folding"></a>
  595. Next: <a rel="next" accesskey="n" href="#Brief">Brief</a>,
  596. Previous: <a rel="previous" accesskey="p" href="#Case-Folding">Case Folding</a>,
  597. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  598.  
  599. </div>
  600.  
  601. <h3 class="section">1.5 Suppressing Lines Matching a Regular Expression</h3>
  602.  
  603. <p><a name="index-regular-expression-suppression-8"></a>
  604. To ignore insertions and deletions of lines that match a
  605. <samp><span class="command">grep</span></samp>-style regular expression, use the <samp><span class="option">-I
  606. </span><var>regexp</var></samp> or <samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp> option. 
  607. You should escape
  608. regular expressions that contain shell metacharacters to prevent the
  609. shell from expanding them.  For example, `<samp><span class="samp">diff -I '^[[:digit:]]'</span></samp>' ignores
  610. all changes to lines beginning with a digit.
  611.  
  612.    <p>However, <samp><span class="option">-I</span></samp> only ignores the insertion or deletion of lines that
  613. contain the regular expression if every changed line in the hunk—every
  614. insertion and every deletion—matches the regular expression.  In other
  615. words, for each nonignorable change, <samp><span class="command">diff</span></samp> prints the complete set
  616. of changes in its vicinity, including the ignorable ones.
  617.  
  618.    <p>You can specify more than one regular expression for lines to ignore by
  619. using more than one <samp><span class="option">-I</span></samp> option.  <samp><span class="command">diff</span></samp> tries to match each
  620. line against each regular expression.
  621.  
  622. <div class="node">
  623. <p><hr>
  624. <a name="Brief"></a>
  625. Next: <a rel="next" accesskey="n" href="#Binary">Binary</a>,
  626. Previous: <a rel="previous" accesskey="p" href="#Specified-Folding">Specified Folding</a>,
  627. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  628.  
  629. </div>
  630.  
  631. <h3 class="section">1.6 Summarizing Which Files Differ</h3>
  632.  
  633. <p><a name="index-summarizing-which-files-differ-9"></a><a name="index-brief-difference-reports-10"></a>
  634. When you only want to find out whether files are different, and you
  635. don't care what the differences are, you can use the summary output
  636. format.  In this format, instead of showing the differences between the
  637. files, <samp><span class="command">diff</span></samp> simply reports whether files differ.  The <samp><span class="option">-q</span></samp>
  638. and <samp><span class="option">--brief</span></samp> options select this output format.
  639.  
  640.    <p>This format is especially useful when comparing the contents of two
  641. directories.  It is also much faster than doing the normal line by line
  642. comparisons, because <samp><span class="command">diff</span></samp> can stop analyzing the files as soon as
  643. it knows that there are any differences.
  644.  
  645.    <p>You can also get a brief indication of whether two files differ by using
  646. <samp><span class="command">cmp</span></samp>.  For files that are identical, <samp><span class="command">cmp</span></samp> produces no
  647. output.  When the files differ, by default, <samp><span class="command">cmp</span></samp> outputs the byte
  648. and line number where the first difference occurs.  You can use
  649. the <samp><span class="option">-s</span></samp> option to suppress that information, so that <samp><span class="command">cmp</span></samp>
  650. produces no output and reports whether the files differ using only its
  651. exit status (see <a href="#Invoking-cmp">Invoking cmp</a>).
  652.  
  653. <!-- Fix this. -->
  654. <p>Unlike <samp><span class="command">diff</span></samp>, <samp><span class="command">cmp</span></samp> cannot compare directories; it can only
  655. compare two files.
  656.  
  657. <div class="node">
  658. <p><hr>
  659. <a name="Binary"></a>
  660. Previous: <a rel="previous" accesskey="p" href="#Brief">Brief</a>,
  661. Up: <a rel="up" accesskey="u" href="#Comparison">Comparison</a>
  662.  
  663. </div>
  664.  
  665. <h3 class="section">1.7 Binary Files and Forcing Text Comparisons</h3>
  666.  
  667. <p><a name="index-binary-file-diff-11"></a><a name="index-text-versus-binary-diff-12"></a>
  668. If <samp><span class="command">diff</span></samp> thinks that either of the two files it is comparing is
  669. binary (a non-text file), it normally treats that pair of files much as
  670. if the summary output format had been selected (see <a href="#Brief">Brief</a>), and
  671. reports only that the binary files are different.  This is because line
  672. by line comparisons are usually not meaningful for binary files.
  673.  
  674.    <p><samp><span class="command">diff</span></samp> determines whether a file is text or binary by checking the
  675. first few bytes in the file; the exact number of bytes is system
  676. dependent, but it is typically several thousand.  If every byte in
  677. that part of the file is non-null, <samp><span class="command">diff</span></samp> considers the file to be
  678. text; otherwise it considers the file to be binary.
  679.  
  680.    <p>Sometimes you might want to force <samp><span class="command">diff</span></samp> to consider files to be
  681. text.  For example, you might be comparing text files that contain
  682. null characters; <samp><span class="command">diff</span></samp> would erroneously decide that those are
  683. non-text files.  Or you might be comparing documents that are in a
  684. format used by a word processing system that uses null characters to
  685. indicate special formatting.  You can force <samp><span class="command">diff</span></samp> to consider all
  686. files to be text files, and compare them line by line, by using the
  687. <samp><span class="option">-a</span></samp> or <samp><span class="option">--text</span></samp> option.  If the files you compare using this
  688. option do not in fact contain text, they will probably contain few
  689. newline characters, and the <samp><span class="command">diff</span></samp> output will consist of hunks
  690. showing differences between long lines of whatever characters the files
  691. contain.
  692.  
  693.    <p>You can also force <samp><span class="command">diff</span></samp> to consider all files to be binary files,
  694. and report only whether they differ (but not how).  Use the
  695. <samp><span class="option">-q</span></samp> or <samp><span class="option">--brief</span></samp> option for this.
  696.  
  697.    <p>Differing binary files are considered to cause trouble because the
  698. resulting <samp><span class="command">diff</span></samp> output does not capture all the differences. 
  699. This trouble causes <samp><span class="command">diff</span></samp> to exit with status 2.  However,
  700. this trouble cannot occur with the <samp><span class="option">--a</span></samp> or <samp><span class="option">--text</span></samp>
  701. option, or with the <samp><span class="option">-q</span></samp> or <samp><span class="option">--brief</span></samp> option, as these
  702. options both cause <samp><span class="command">diff</span></samp> to treat binary files like text
  703. files.
  704.  
  705.    <p>In operating systems that distinguish between text and binary files,
  706. <samp><span class="command">diff</span></samp> normally reads and writes all data as text.  Use the
  707. <samp><span class="option">--binary</span></samp> option to force <samp><span class="command">diff</span></samp> to read and write binary
  708. data instead.  This option has no effect on a <span class="sc">posix</span>-compliant system
  709. like <span class="sc">gnu</span> or traditional Unix.  However, many personal computer
  710. operating systems represent the end of a line with a carriage return
  711. followed by a newline.  On such systems, <samp><span class="command">diff</span></samp> normally ignores
  712. these carriage returns on input and generates them at the end of each
  713. output line, but with the <samp><span class="option">--binary</span></samp> option <samp><span class="command">diff</span></samp> treats
  714. each carriage return as just another input character, and does not
  715. generate a carriage return at the end of each output line.  This can be
  716. useful when dealing with non-text files that are meant to be
  717. interchanged with <span class="sc">posix</span>-compliant systems.
  718.  
  719.    <p>The <samp><span class="option">--strip-trailing-cr</span></samp> causes <samp><span class="command">diff</span></samp> to treat input
  720. lines that end in carriage return followed by newline as if they end
  721. in plain newline.  This can be useful when comparing text that is
  722. imperfectly imported from many personal computer operating systems. 
  723. This option affects how lines are read, which in turn affects how they
  724. are compared and output.
  725.  
  726.    <p>If you want to compare two files byte by byte, you can use the
  727. <samp><span class="command">cmp</span></samp> program with the <samp><span class="option">-l</span></samp> option to show the values
  728. of each differing byte in the two files.  With <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>,
  729. you can also use the <samp><span class="option">-b</span></samp> option to show the <span class="sc">ascii</span>
  730. representation of those bytes.  See <a href="#Invoking-cmp">Invoking cmp</a>, for more
  731. information.
  732.  
  733.    <p>If <samp><span class="command">diff3</span></samp> thinks that any of the files it is comparing is binary
  734. (a non-text file), it normally reports an error, because such
  735. comparisons are usually not useful.  <samp><span class="command">diff3</span></samp> uses the same test as
  736. <samp><span class="command">diff</span></samp> to decide whether a file is binary.  As with <samp><span class="command">diff</span></samp>, if
  737. the input files contain a few non-text bytes but otherwise are like
  738. text files, you can force <samp><span class="command">diff3</span></samp> to consider all files to be text
  739. files and compare them line by line by using the <samp><span class="option">-a</span></samp> or
  740. <samp><span class="option">--text</span></samp> options.
  741.  
  742. <div class="node">
  743. <p><hr>
  744. <a name="Output-Formats"></a>
  745. Next: <a rel="next" accesskey="n" href="#Incomplete-Lines">Incomplete Lines</a>,
  746. Previous: <a rel="previous" accesskey="p" href="#Comparison">Comparison</a>,
  747. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  748.  
  749. </div>
  750.  
  751. <h2 class="chapter">2 <samp><span class="command">diff</span></samp> Output Formats</h2>
  752.  
  753. <p><a name="index-output-formats-13"></a><a name="index-format-of-_0040command_007bdiff_007d-output-14"></a>
  754. <samp><span class="command">diff</span></samp> has several mutually exclusive options for output format. 
  755. The following sections describe each format, illustrating how
  756. <samp><span class="command">diff</span></samp> reports the differences between two sample input files.
  757.  
  758. <ul class="menu">
  759. <li><a accesskey="1" href="#Sample-diff-Input">Sample diff Input</a>:  Sample <samp><span class="command">diff</span></samp> input files for examples. 
  760. <li><a accesskey="2" href="#Normal">Normal</a>:             Showing differences without surrounding text. 
  761. <li><a accesskey="3" href="#Context">Context</a>:            Showing differences with the surrounding text. 
  762. <li><a accesskey="4" href="#Side-by-Side">Side by Side</a>:       Showing differences in two columns. 
  763. <li><a accesskey="5" href="#Scripts">Scripts</a>:            Generating scripts for other programs. 
  764. <li><a accesskey="6" href="#If_002dthen_002delse">If-then-else</a>:       Merging files with if-then-else. 
  765. </ul>
  766.  
  767. <div class="node">
  768. <p><hr>
  769. <a name="Sample-diff-Input"></a>
  770. Next: <a rel="next" accesskey="n" href="#Normal">Normal</a>,
  771. Up: <a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>
  772.  
  773. </div>
  774.  
  775. <h3 class="section">2.1 Two Sample Input Files</h3>
  776.  
  777. <p><a name="index-g_t_0040command_007bdiff_007d-sample-input-15"></a><a name="index-sample-input-for-_0040command_007bdiff_007d-16"></a>
  778. Here are two sample files that we will use in numerous examples to
  779. illustrate the output of <samp><span class="command">diff</span></samp> and how various options can change
  780. it.
  781.  
  782.    <p>This is the file <samp><span class="file">lao</span></samp>:
  783.  
  784. <pre class="example">     The Way that can be told of is not the eternal Way;
  785.      The name that can be named is not the eternal name.
  786.      The Nameless is the origin of Heaven and Earth;
  787.      The Named is the mother of all things.
  788.      Therefore let there always be non-being,
  789.        so we may see their subtlety,
  790.      And let there always be being,
  791.        so we may see their outcome.
  792.      The two are the same,
  793.      But after they are produced,
  794.        they have different names.
  795. </pre>
  796.    <p>This is the file <samp><span class="file">tzu</span></samp>:
  797.  
  798. <pre class="example">     The Nameless is the origin of Heaven and Earth;
  799.      The named is the mother of all things.
  800.      
  801.      Therefore let there always be non-being,
  802.        so we may see their subtlety,
  803.      And let there always be being,
  804.        so we may see their outcome.
  805.      The two are the same,
  806.      But after they are produced,
  807.        they have different names.
  808.      They both may be called deep and profound.
  809.      Deeper and more profound,
  810.      The door of all subtleties!
  811. </pre>
  812.    <p>In this example, the first hunk contains just the first two lines of
  813. <samp><span class="file">lao</span></samp>, the second hunk contains the fourth line of <samp><span class="file">lao</span></samp>
  814. opposing the second and third lines of <samp><span class="file">tzu</span></samp>, and the last hunk
  815. contains just the last three lines of <samp><span class="file">tzu</span></samp>.
  816.  
  817. <div class="node">
  818. <p><hr>
  819. <a name="Normal"></a>
  820. Next: <a rel="next" accesskey="n" href="#Context">Context</a>,
  821. Previous: <a rel="previous" accesskey="p" href="#Sample-diff-Input">Sample diff Input</a>,
  822. Up: <a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>
  823.  
  824. </div>
  825.  
  826. <h3 class="section">2.2 Showing Differences Without Context</h3>
  827.  
  828. <p><a name="index-normal-output-format-17"></a><a name="index-g_t_0040samp_007b_003c_007d-output-format-18"></a>
  829. The “normal” <samp><span class="command">diff</span></samp> output format shows each hunk of differences
  830. without any surrounding context.  Sometimes such output is the clearest
  831. way to see how lines have changed, without the clutter of nearby
  832. unchanged lines (although you can get similar results with the context
  833. or unified formats by using 0 lines of context).  However, this format
  834. is no longer widely used for sending out patches; for that purpose, the
  835. context format (see <a href="#Context-Format">Context Format</a>) and the unified format
  836. (see <a href="#Unified-Format">Unified Format</a>) are superior.  Normal format is the default for
  837. compatibility with older versions of <samp><span class="command">diff</span></samp> and the <span class="sc">posix</span>
  838. standard.  Use the <samp><span class="option">--normal</span></samp> option to select this output
  839. format explicitly.
  840.  
  841. <ul class="menu">
  842. <li><a accesskey="1" href="#Detailed-Normal">Detailed Normal</a>:  A detailed description of normal output format. 
  843. <li><a accesskey="2" href="#Example-Normal">Example Normal</a>:   Sample output in the normal format. 
  844. </ul>
  845.  
  846. <div class="node">
  847. <p><hr>
  848. <a name="Detailed-Normal"></a>
  849. Next: <a rel="next" accesskey="n" href="#Example-Normal">Example Normal</a>,
  850. Up: <a rel="up" accesskey="u" href="#Normal">Normal</a>
  851.  
  852. </div>
  853.  
  854. <h4 class="subsection">2.2.1 Detailed Description of Normal Format</h4>
  855.  
  856. <p>The normal output format consists of one or more hunks of differences;
  857. each hunk shows one area where the files differ.  Normal format hunks
  858. look like this:
  859.  
  860. <pre class="example">     <var>change-command</var>
  861.      < <var>from-file-line</var>
  862.      < <var>from-file-line</var>...
  863.      ---
  864.      > <var>to-file-line</var>
  865.      > <var>to-file-line</var>...
  866. </pre>
  867.    <p>There are three types of change commands.  Each consists of a line
  868. number or comma-separated range of lines in the first file, a single
  869. character indicating the kind of change to make, and a line number or
  870. comma-separated range of lines in the second file.  All line numbers are
  871. the original line numbers in each file.  The types of change commands
  872. are:
  873.  
  874.      <dl>
  875. <dt>`<samp><var>l</var><span class="samp">a</span><var>r</var></samp>'<dd>Add the lines in range <var>r</var> of the second file after line <var>l</var> of
  876. the first file.  For example, `<samp><span class="samp">8a12,15</span></samp>' means append lines 12–15
  877. of file 2 after line 8 of file 1; or, if changing file 2 into file 1,
  878. delete lines 12–15 of file 2.
  879.  
  880.      <br><dt>`<samp><var>f</var><span class="samp">c</span><var>t</var></samp>'<dd>Replace the lines in range <var>f</var> of the first file with lines in range
  881. <var>t</var> of the second file.  This is like a combined add and delete, but
  882. more compact.  For example, `<samp><span class="samp">5,7c8,10</span></samp>' means change lines 5–7 of
  883. file 1 to read as lines 8–10 of file 2; or, if changing file 2 into
  884. file 1, change lines 8–10 of file 2 to read as lines 5–7 of file 1.
  885.  
  886.      <br><dt>`<samp><var>r</var><span class="samp">d</span><var>l</var></samp>'<dd>Delete the lines in range <var>r</var> from the first file; line <var>l</var> is where
  887. they would have appeared in the second file had they not been deleted. 
  888. For example, `<samp><span class="samp">5,7d3</span></samp>' means delete lines 5–7 of file 1; or, if
  889. changing file 2 into file 1, append lines 5–7 of file 1 after line 3 of
  890. file 2. 
  891. </dl>
  892.  
  893. <div class="node">
  894. <p><hr>
  895. <a name="Example-Normal"></a>
  896. Previous: <a rel="previous" accesskey="p" href="#Detailed-Normal">Detailed Normal</a>,
  897. Up: <a rel="up" accesskey="u" href="#Normal">Normal</a>
  898.  
  899. </div>
  900.  
  901. <h4 class="subsection">2.2.2 An Example of Normal Format</h4>
  902.  
  903. <p>Here is the output of the command `<samp><span class="samp">diff lao tzu</span></samp>'
  904. (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files). 
  905. Notice that it shows only the lines that are different between the two
  906. files.
  907.  
  908. <pre class="example">     1,2d0
  909.      < The Way that can be told of is not the eternal Way;
  910.      < The name that can be named is not the eternal name.
  911.      4c2,3
  912.      < The Named is the mother of all things.
  913.      ---
  914.      > The named is the mother of all things.
  915.      >
  916.      11a11,13
  917.      > They both may be called deep and profound.
  918.      > Deeper and more profound,
  919.      > The door of all subtleties!
  920. </pre>
  921.    <div class="node">
  922. <p><hr>
  923. <a name="Context"></a>
  924. Next: <a rel="next" accesskey="n" href="#Side-by-Side">Side by Side</a>,
  925. Previous: <a rel="previous" accesskey="p" href="#Normal">Normal</a>,
  926. Up: <a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>
  927.  
  928. </div>
  929.  
  930. <h3 class="section">2.3 Showing Differences in Their Context</h3>
  931.  
  932. <p><a name="index-context-output-format-19"></a><a name="index-g_t_0040samp_007b_0021_007d-output-format-20"></a>
  933. Usually, when you are looking at the differences between files, you will
  934. also want to see the parts of the files near the lines that differ, to
  935. help you understand exactly what has changed.  These nearby parts of the
  936. files are called the <dfn>context</dfn>.
  937.  
  938.    <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> provides two output formats that show context
  939. around the differing lines: <dfn>context format</dfn> and <dfn>unified
  940. format</dfn>.  It can optionally show in which function or section of the
  941. file the differing lines are found.
  942.  
  943.    <p>If you are distributing new versions of files to other people in the
  944. form of <samp><span class="command">diff</span></samp> output, you should use one of the output formats
  945. that show context so that they can apply the diffs even if they have
  946. made small changes of their own to the files.  <samp><span class="command">patch</span></samp> can apply
  947. the diffs in this case by searching in the files for the lines of
  948. context around the differing lines; if those lines are actually a few
  949. lines away from where the diff says they are, <samp><span class="command">patch</span></samp> can adjust
  950. the line numbers accordingly and still apply the diff correctly. 
  951. See <a href="#Imperfect">Imperfect</a>, for more information on using <samp><span class="command">patch</span></samp> to apply
  952. imperfect diffs.
  953.  
  954. <ul class="menu">
  955. <li><a accesskey="1" href="#Context-Format">Context Format</a>:   An output format that shows surrounding lines. 
  956. <li><a accesskey="2" href="#Unified-Format">Unified Format</a>:   A more compact output format that shows context. 
  957. <li><a accesskey="3" href="#Sections">Sections</a>:         Showing which sections of the files differences are in. 
  958. <li><a accesskey="4" href="#Alternate-Names">Alternate Names</a>:  Showing alternate file names in context headers. 
  959. </ul>
  960.  
  961. <div class="node">
  962. <p><hr>
  963. <a name="Context-Format"></a>
  964. Next: <a rel="next" accesskey="n" href="#Unified-Format">Unified Format</a>,
  965. Up: <a rel="up" accesskey="u" href="#Context">Context</a>
  966.  
  967. </div>
  968.  
  969. <h4 class="subsection">2.3.1 Context Format</h4>
  970.  
  971. <p>The context output format shows several lines of context around the
  972. lines that differ.  It is the standard format for distributing updates
  973. to source code.
  974.  
  975.    <p>To select this output format, use the <samp><span class="option">-C </span><var>lines</var></samp>,
  976. <samp><span class="option">--context[=</span><var>lines</var><span class="option">]</span></samp>, or <samp><span class="option">-c</span></samp> option.  The
  977. argument <var>lines</var> that some of these options take is the number of
  978. lines of context to show.  If you do not specify <var>lines</var>, it
  979. defaults to three.  For proper operation, <samp><span class="command">patch</span></samp> typically needs
  980. at least two lines of context.
  981.  
  982. <ul class="menu">
  983. <li><a accesskey="1" href="#Detailed-Context">Detailed Context</a>:  A detailed description of the context output format. 
  984. <li><a accesskey="2" href="#Example-Context">Example Context</a>:   Sample output in context format. 
  985. <li><a accesskey="3" href="#Less-Context">Less Context</a>:      Another sample with less context. 
  986. </ul>
  987.  
  988. <div class="node">
  989. <p><hr>
  990. <a name="Detailed-Context"></a>
  991. Next: <a rel="next" accesskey="n" href="#Example-Context">Example Context</a>,
  992. Up: <a rel="up" accesskey="u" href="#Context-Format">Context Format</a>
  993.  
  994. </div>
  995.  
  996. <h5 class="subsubsection">2.3.1.1 Detailed Description of Context Format</h5>
  997.  
  998. <p>The context output format starts with a two-line header, which looks
  999. like this:
  1000.  
  1001. <pre class="example">     *** <var>from-file</var> <var>from-file-modification-time</var>
  1002.      --- <var>to-file</var> <var>to-file-modification time</var>
  1003. </pre>
  1004.    <p class="noindent"><a name="index-LC_005fTIME-21"></a><a name="index-time-stamp-format_002c-context-diffs-22"></a>The time stamp normally looks like `<samp><span class="samp">2002-02-21 23:30:39.942229878
  1005. -0800</span></samp>' to indicate the date, time with fractional seconds, and time
  1006. zone in <a href="ftp://ftp.isi.edu/in-notes/rfc2822.txt">Internet RFC 2822 format</a>.  However, a traditional time stamp like `<samp><span class="samp">Thu Feb 21
  1007. 23:30:39 2002</span></samp>' is used if the <samp><span class="env">LC_TIME</span></samp> locale category is either
  1008. `<samp><span class="samp">C</span></samp>' or `<samp><span class="samp">POSIX</span></samp>'.
  1009.  
  1010.    <p>You can change the header's content with the
  1011. <samp><span class="option">--label=</span><var>label</var></samp> option; see <a href="#Alternate-Names">Alternate Names</a>.
  1012.  
  1013.    <p>Next come one or more hunks of differences; each hunk shows one area
  1014. where the files differ.  Context format hunks look like this:
  1015.  
  1016. <pre class="example">     ***************
  1017.      *** <var>from-file-line-range</var> ****
  1018.        <var>from-file-line</var>
  1019.        <var>from-file-line</var>...
  1020.      --- <var>to-file-line-range</var> ----
  1021.        <var>to-file-line</var>
  1022.        <var>to-file-line</var>...
  1023. </pre>
  1024.    <p>The lines of context around the lines that differ start with two space
  1025. characters.  The lines that differ between the two files start with one
  1026. of the following indicator characters, followed by a space character:
  1027.  
  1028.      <dl>
  1029. <dt>`<samp><span class="samp">!</span></samp>'<dd>A line that is part of a group of one or more lines that changed between
  1030. the two files.  There is a corresponding group of lines marked with
  1031. `<samp><span class="samp">!</span></samp>' in the part of this hunk for the other file.
  1032.  
  1033.      <br><dt>`<samp><span class="samp">+</span></samp>'<dd>An “inserted” line in the second file that corresponds to nothing in
  1034. the first file.
  1035.  
  1036.      <br><dt>`<samp><span class="samp">-</span></samp>'<dd>A “deleted” line in the first file that corresponds to nothing in the
  1037. second file. 
  1038. </dl>
  1039.  
  1040.    <p>If all of the changes in a hunk are insertions, the lines of
  1041. <var>from-file</var> are omitted.  If all of the changes are deletions, the
  1042. lines of <var>to-file</var> are omitted.
  1043.  
  1044. <div class="node">
  1045. <p><hr>
  1046. <a name="Example-Context"></a>
  1047. Next: <a rel="next" accesskey="n" href="#Less-Context">Less Context</a>,
  1048. Previous: <a rel="previous" accesskey="p" href="#Detailed-Context">Detailed Context</a>,
  1049. Up: <a rel="up" accesskey="u" href="#Context-Format">Context Format</a>
  1050.  
  1051. </div>
  1052.  
  1053. <h5 class="subsubsection">2.3.1.2 An Example of Context Format</h5>
  1054.  
  1055. <p>Here is the output of `<samp><span class="samp">diff -c lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>,
  1056. for the complete contents of the two files).  Notice that up to three
  1057. lines that are not different are shown around each line that is
  1058. different; they are the context lines.  Also notice that the first two
  1059. hunks have run together, because their contents overlap.
  1060.  
  1061. <pre class="example">     *** lao    2002-02-21 23:30:39.942229878 -0800
  1062.      --- tzu    2002-02-21 23:30:50.442260588 -0800
  1063.      ***************
  1064.      *** 1,7 ****
  1065.      - The Way that can be told of is not the eternal Way;
  1066.      - The name that can be named is not the eternal name.
  1067.        The Nameless is the origin of Heaven and Earth;
  1068.      ! The Named is the mother of all things.
  1069.        Therefore let there always be non-being,
  1070.          so we may see their subtlety,
  1071.        And let there always be being,
  1072.      --- 1,6 ----
  1073.        The Nameless is the origin of Heaven and Earth;
  1074.      ! The named is the mother of all things.
  1075.      !
  1076.        Therefore let there always be non-being,
  1077.          so we may see their subtlety,
  1078.        And let there always be being,
  1079.      ***************
  1080.      *** 9,11 ****
  1081.      --- 8,13 ----
  1082.        The two are the same,
  1083.        But after they are produced,
  1084.          they have different names.
  1085.      + They both may be called deep and profound.
  1086.      + Deeper and more profound,
  1087.      + The door of all subtleties!
  1088. </pre>
  1089.    <div class="node">
  1090. <p><hr>
  1091. <a name="Less-Context"></a>
  1092. Previous: <a rel="previous" accesskey="p" href="#Example-Context">Example Context</a>,
  1093. Up: <a rel="up" accesskey="u" href="#Context-Format">Context Format</a>
  1094.  
  1095. </div>
  1096.  
  1097. <h5 class="subsubsection">2.3.1.3 An Example of Context Format with Less Context</h5>
  1098.  
  1099. <p>Here is the output of `<samp><span class="samp">diff -C 1 lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).  Notice that at
  1100. most one context line is reported here.
  1101.  
  1102. <pre class="example">     *** lao    2002-02-21 23:30:39.942229878 -0800
  1103.      --- tzu    2002-02-21 23:30:50.442260588 -0800
  1104.      ***************
  1105.      *** 1,5 ****
  1106.      - The Way that can be told of is not the eternal Way;
  1107.      - The name that can be named is not the eternal name.
  1108.        The Nameless is the origin of Heaven and Earth;
  1109.      ! The Named is the mother of all things.
  1110.        Therefore let there always be non-being,
  1111.      --- 1,4 ----
  1112.        The Nameless is the origin of Heaven and Earth;
  1113.      ! The named is the mother of all things.
  1114.      !
  1115.        Therefore let there always be non-being,
  1116.      ***************
  1117.      *** 11 ****
  1118.      --- 10,13 ----
  1119.          they have different names.
  1120.      + They both may be called deep and profound.
  1121.      + Deeper and more profound,
  1122.      + The door of all subtleties!
  1123. </pre>
  1124.    <div class="node">
  1125. <p><hr>
  1126. <a name="Unified-Format"></a>
  1127. Next: <a rel="next" accesskey="n" href="#Sections">Sections</a>,
  1128. Previous: <a rel="previous" accesskey="p" href="#Context-Format">Context Format</a>,
  1129. Up: <a rel="up" accesskey="u" href="#Context">Context</a>
  1130.  
  1131. </div>
  1132.  
  1133. <h4 class="subsection">2.3.2 Unified Format</h4>
  1134.  
  1135. <p><a name="index-unified-output-format-23"></a><a name="index-g_t_0040samp_007b_002b_002d_007d-output-format-24"></a>
  1136. The unified output format is a variation on the context format that is
  1137. more compact because it omits redundant context lines.  To select this
  1138. output format, use the <samp><span class="option">-U </span><var>lines</var></samp>,
  1139. <samp><span class="option">--unified[=</span><var>lines</var><span class="option">]</span></samp>, or <samp><span class="option">-u</span></samp>
  1140. option.  The argument <var>lines</var> is the number of lines of context to
  1141. show.  When it is not given, it defaults to three.
  1142.  
  1143.    <p>At present, only <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can produce this format and
  1144. only <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> can automatically apply diffs in this
  1145. format.  For proper operation, <samp><span class="command">patch</span></samp> typically needs at
  1146. least three lines of context.
  1147.  
  1148. <ul class="menu">
  1149. <li><a accesskey="1" href="#Detailed-Unified">Detailed Unified</a>:  A detailed description of unified format. 
  1150. <li><a accesskey="2" href="#Example-Unified">Example Unified</a>:   Sample output in unified format. 
  1151. </ul>
  1152.  
  1153. <div class="node">
  1154. <p><hr>
  1155. <a name="Detailed-Unified"></a>
  1156. Next: <a rel="next" accesskey="n" href="#Example-Unified">Example Unified</a>,
  1157. Up: <a rel="up" accesskey="u" href="#Unified-Format">Unified Format</a>
  1158.  
  1159. </div>
  1160.  
  1161. <h5 class="subsubsection">2.3.2.1 Detailed Description of Unified Format</h5>
  1162.  
  1163. <p>The unified output format starts with a two-line header, which looks
  1164. like this:
  1165.  
  1166. <pre class="example">     --- <var>from-file</var> <var>from-file-modification-time</var>
  1167.      +++ <var>to-file</var> <var>to-file-modification-time</var>
  1168. </pre>
  1169.    <p class="noindent"><a name="index-time-stamp-format_002c-unified-diffs-25"></a>The time stamp looks like `<samp><span class="samp">2002-02-21 23:30:39.942229878 -0800</span></samp>'
  1170. to indicate the date, time with fractional seconds, and time zone.
  1171.  
  1172.    <p>You can change the header's content with the
  1173. <samp><span class="option">--label=</span><var>label</var></samp> option; see See <a href="#Alternate-Names">Alternate Names</a>.
  1174.  
  1175.    <p>Next come one or more hunks of differences; each hunk shows one area
  1176. where the files differ.  Unified format hunks look like this:
  1177.  
  1178. <pre class="example">     @@ <var>from-file-range</var> <var>to-file-range</var> @@
  1179.       <var>line-from-either-file</var>
  1180.       <var>line-from-either-file</var>...
  1181. </pre>
  1182.    <p>The lines common to both files begin with a space character.  The lines
  1183. that actually differ between the two files have one of the following
  1184. indicator characters in the left print column:
  1185.  
  1186.      <dl>
  1187. <dt>`<samp><span class="samp">+</span></samp>'<dd>A line was added here to the first file.
  1188.  
  1189.      <br><dt>`<samp><span class="samp">-</span></samp>'<dd>A line was removed here from the first file. 
  1190. </dl>
  1191.  
  1192. <div class="node">
  1193. <p><hr>
  1194. <a name="Example-Unified"></a>
  1195. Previous: <a rel="previous" accesskey="p" href="#Detailed-Unified">Detailed Unified</a>,
  1196. Up: <a rel="up" accesskey="u" href="#Unified-Format">Unified Format</a>
  1197.  
  1198. </div>
  1199.  
  1200. <h5 class="subsubsection">2.3.2.2 An Example of Unified Format</h5>
  1201.  
  1202. <p>Here is the output of the command `<samp><span class="samp">diff -u lao tzu</span></samp>'
  1203. (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
  1204.  
  1205. <pre class="example">     --- lao    2002-02-21 23:30:39.942229878 -0800
  1206.      +++ tzu    2002-02-21 23:30:50.442260588 -0800
  1207.      @@ -1,7 +1,6 @@
  1208.      -The Way that can be told of is not the eternal Way;
  1209.      -The name that can be named is not the eternal name.
  1210.       The Nameless is the origin of Heaven and Earth;
  1211.      -The Named is the mother of all things.
  1212.      +The named is the mother of all things.
  1213.      +
  1214.       Therefore let there always be non-being,
  1215.         so we may see their subtlety,
  1216.       And let there always be being,
  1217.      @@ -9,3 +8,6 @@
  1218.       The two are the same,
  1219.       But after they are produced,
  1220.         they have different names.
  1221.      +They both may be called deep and profound.
  1222.      +Deeper and more profound,
  1223.      +The door of all subtleties!
  1224. </pre>
  1225.    <div class="node">
  1226. <p><hr>
  1227. <a name="Sections"></a>
  1228. Next: <a rel="next" accesskey="n" href="#Alternate-Names">Alternate Names</a>,
  1229. Previous: <a rel="previous" accesskey="p" href="#Unified-Format">Unified Format</a>,
  1230. Up: <a rel="up" accesskey="u" href="#Context">Context</a>
  1231.  
  1232. </div>
  1233.  
  1234. <h4 class="subsection">2.3.3 Showing Which Sections Differences Are in</h4>
  1235.  
  1236. <p><a name="index-headings-26"></a><a name="index-section-headings-27"></a>
  1237. Sometimes you might want to know which part of the files each change
  1238. falls in.  If the files are source code, this could mean which function
  1239. was changed.  If the files are documents, it could mean which chapter or
  1240. appendix was changed.  <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can show this by displaying the
  1241. nearest section heading line that precedes the differing lines.  Which
  1242. lines are “section headings” is determined by a regular expression.
  1243.  
  1244. <ul class="menu">
  1245. <li><a accesskey="1" href="#Specified-Headings">Specified Headings</a>:   Showing headings that match regular expressions. 
  1246. <li><a accesskey="2" href="#C-Function-Headings">C Function Headings</a>:  Showing headings of C functions. 
  1247. </ul>
  1248.  
  1249. <div class="node">
  1250. <p><hr>
  1251. <a name="Specified-Headings"></a>
  1252. Next: <a rel="next" accesskey="n" href="#C-Function-Headings">C Function Headings</a>,
  1253. Up: <a rel="up" accesskey="u" href="#Sections">Sections</a>
  1254.  
  1255. </div>
  1256.  
  1257. <h5 class="subsubsection">2.3.3.1 Showing Lines That Match Regular Expressions</h5>
  1258.  
  1259. <p><a name="index-specified-headings-28"></a><a name="index-regular-expression-matching-headings-29"></a>
  1260. To show in which sections differences occur for files that are not
  1261. source code for C or similar languages, use the <samp><span class="option">-F </span><var>regexp</var></samp>
  1262. or <samp><span class="option">--show-function-line=</span><var>regexp</var></samp> option.  <samp><span class="command">diff</span></samp>
  1263. considers lines that match the <samp><span class="command">grep</span></samp>-style regular expression
  1264. <var>regexp</var> to be the beginning
  1265. of a section of the file.  Here are suggested regular expressions for
  1266. some common languages:
  1267.  
  1268. <!-- Please add to this list, e.g. Fortran, Pascal, Perl, Python. -->
  1269. <dl>
  1270. <dt>`<samp><span class="samp">^[[:alpha:]$_]</span></samp>'<dd>C, C++, Prolog
  1271. <br><dt>`<samp><span class="samp">^(</span></samp>'<dd>Lisp
  1272. <br><dt>`<samp><span class="samp">^@node</span></samp>'<dd>Texinfo
  1273. </dl>
  1274.  
  1275.    <p>This option does not automatically select an output format; in order to
  1276. use it, you must select the context format (see <a href="#Context-Format">Context Format</a>) or
  1277. unified format (see <a href="#Unified-Format">Unified Format</a>).  In other output formats it
  1278. has no effect.
  1279.  
  1280.    <p>The <samp><span class="option">-F</span></samp> and <samp><span class="option">--show-function-line</span></samp> options find the nearest
  1281. unchanged line that precedes each hunk of differences and matches the
  1282. given regular expression.  Then they add that line to the end of the
  1283. line of asterisks in the context format, or to the `<samp><span class="samp">@@</span></samp>' line in
  1284. unified format.  If no matching line exists, they leave the output for
  1285. that hunk unchanged.  If that line is more than 40 characters long, they
  1286. output only the first 40 characters.  You can specify more than one
  1287. regular expression for such lines; <samp><span class="command">diff</span></samp> tries to match each line
  1288. against each regular expression, starting with the last one given.  This
  1289. means that you can use <samp><span class="option">-p</span></samp> and <samp><span class="option">-F</span></samp> together, if you wish.
  1290.  
  1291. <div class="node">
  1292. <p><hr>
  1293. <a name="C-Function-Headings"></a>
  1294. Previous: <a rel="previous" accesskey="p" href="#Specified-Headings">Specified Headings</a>,
  1295. Up: <a rel="up" accesskey="u" href="#Sections">Sections</a>
  1296.  
  1297. </div>
  1298.  
  1299. <h5 class="subsubsection">2.3.3.2 Showing C Function Headings</h5>
  1300.  
  1301. <p><a name="index-C-function-headings-30"></a><a name="index-function-headings_002c-C-31"></a>
  1302. To show in which functions differences occur for C and similar
  1303. languages, you can use the <samp><span class="option">-p</span></samp> or <samp><span class="option">--show-c-function</span></samp> option. 
  1304. This option automatically defaults to the context output format
  1305. (see <a href="#Context-Format">Context Format</a>), with the default number of lines of context. 
  1306. You can override that number with <samp><span class="option">-C </span><var>lines</var></samp> elsewhere in the
  1307. command line.  You can override both the format and the number with
  1308. <samp><span class="option">-U </span><var>lines</var></samp> elsewhere in the command line.
  1309.  
  1310.    <p>The <samp><span class="option">-p</span></samp> and <samp><span class="option">--show-c-function</span></samp> options are equivalent to
  1311. <samp><span class="option">-F '^[[:alpha:]$_]'</span></samp> if the unified format is specified, otherwise
  1312. <samp><span class="option">-c -F '^[[:alpha:]$_]'</span></samp> (see <a href="#Specified-Headings">Specified Headings</a>).  <span class="sc">gnu</span>
  1313. <samp><span class="command">diff</span></samp> provides them for the sake of convenience.
  1314.  
  1315. <div class="node">
  1316. <p><hr>
  1317. <a name="Alternate-Names"></a>
  1318. Previous: <a rel="previous" accesskey="p" href="#Sections">Sections</a>,
  1319. Up: <a rel="up" accesskey="u" href="#Context">Context</a>
  1320.  
  1321. </div>
  1322.  
  1323. <h4 class="subsection">2.3.4 Showing Alternate File Names</h4>
  1324.  
  1325. <p><a name="index-alternate-file-names-32"></a><a name="index-file-name-alternates-33"></a>
  1326. If you are comparing two files that have meaningless or uninformative
  1327. names, you might want <samp><span class="command">diff</span></samp> to show alternate names in the header
  1328. of the context and unified output formats.  To do this, use the
  1329. <samp><span class="option">--label=</span><var>label</var></samp> option.  The first time
  1330. you give this option, its argument replaces the name and date of the
  1331. first file in the header; the second time, its argument replaces the
  1332. name and date of the second file.  If you give this option more than
  1333. twice, <samp><span class="command">diff</span></samp> reports an error.  The <samp><span class="option">--label</span></samp> option does not
  1334. affect the file names in the <samp><span class="command">pr</span></samp> header when the <samp><span class="option">-l</span></samp> or
  1335. <samp><span class="option">--paginate</span></samp> option is used (see <a href="#Pagination">Pagination</a>).
  1336.  
  1337.    <p>Here are the first two lines of the output from `<samp><span class="samp">diff -C 2
  1338. --label=original --label=modified lao tzu</span></samp>':
  1339.  
  1340. <pre class="example">     *** original
  1341.      --- modified
  1342. </pre>
  1343.    <div class="node">
  1344. <p><hr>
  1345. <a name="Side-by-Side"></a>
  1346. Next: <a rel="next" accesskey="n" href="#Scripts">Scripts</a>,
  1347. Previous: <a rel="previous" accesskey="p" href="#Context">Context</a>,
  1348. Up: <a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>
  1349.  
  1350. </div>
  1351.  
  1352. <h3 class="section">2.4 Showing Differences Side by Side</h3>
  1353.  
  1354. <p><a name="index-side-by-side-34"></a><a name="index-two_002dcolumn-output-35"></a><a name="index-columnar-output-36"></a>
  1355. <samp><span class="command">diff</span></samp> can produce a side by side difference listing of two files. 
  1356. The files are listed in two columns with a gutter between them.  The
  1357. gutter contains one of the following markers:
  1358.  
  1359.      <dl>
  1360. <dt>white space<dd>The corresponding lines are in common.  That is, either the lines are
  1361. identical, or the difference is ignored because of one of the
  1362. <samp><span class="option">--ignore</span></samp> options (see <a href="#White-Space">White Space</a>).
  1363.  
  1364.      <br><dt>`<samp><span class="samp">|</span></samp>'<dd>The corresponding lines differ, and they are either both complete
  1365. or both incomplete.
  1366.  
  1367.      <br><dt>`<samp><span class="samp"><</span></samp>'<dd>The files differ and only the first file contains the line.
  1368.  
  1369.      <br><dt>`<samp><span class="samp">></span></samp>'<dd>The files differ and only the second file contains the line.
  1370.  
  1371.      <br><dt>`<samp><span class="samp">(</span></samp>'<dd>Only the first file contains the line, but the difference is ignored.
  1372.  
  1373.      <br><dt>`<samp><span class="samp">)</span></samp>'<dd>Only the second file contains the line, but the difference is ignored.
  1374.  
  1375.      <br><dt>`<samp><span class="samp">\</span></samp>'<dd>The corresponding lines differ, and only the first line is incomplete.
  1376.  
  1377.      <br><dt>`<samp><span class="samp">/</span></samp>'<dd>The corresponding lines differ, and only the second line is incomplete. 
  1378. </dl>
  1379.  
  1380.    <p>Normally, an output line is incomplete if and only if the lines that it
  1381. contains are incomplete; See <a href="#Incomplete-Lines">Incomplete Lines</a>.  However, when an
  1382. output line represents two differing lines, one might be incomplete
  1383. while the other is not.  In this case, the output line is complete,
  1384. but its the gutter is marked `<samp><span class="samp">\</span></samp>' if the first line is incomplete,
  1385. `<samp><span class="samp">/</span></samp>' if the second line is.
  1386.  
  1387.    <p>Side by side format is sometimes easiest to read, but it has limitations. 
  1388. It generates much wider output than usual, and truncates lines that are
  1389. too long to fit.  Also, it relies on lining up output more heavily than
  1390. usual, so its output looks particularly bad if you use varying
  1391. width fonts, nonstandard tab stops, or nonprinting characters.
  1392.  
  1393.    <p>You can use the <samp><span class="command">sdiff</span></samp> command to interactively merge side by side
  1394. differences.  See <a href="#Interactive-Merging">Interactive Merging</a>, for more information on merging files.
  1395.  
  1396. <ul class="menu">
  1397. <li><a accesskey="1" href="#Side-by-Side-Format">Side by Side Format</a>:   Controlling side by side output format. 
  1398. <li><a accesskey="2" href="#Example-Side-by-Side">Example Side by Side</a>:  Sample side by side output. 
  1399. </ul>
  1400.  
  1401. <div class="node">
  1402. <p><hr>
  1403. <a name="Side-by-Side-Format"></a>
  1404. Next: <a rel="next" accesskey="n" href="#Example-Side-by-Side">Example Side by Side</a>,
  1405. Up: <a rel="up" accesskey="u" href="#Side-by-Side">Side by Side</a>
  1406.  
  1407. </div>
  1408.  
  1409. <h4 class="subsection">2.4.1 Controlling Side by Side Format</h4>
  1410.  
  1411. <p><a name="index-side-by-side-format-37"></a>
  1412. The <samp><span class="option">-y</span></samp> or <samp><span class="option">--side-by-side</span></samp> option selects side by side
  1413. format.  Because side by side output lines contain two input lines, the
  1414. output is wider than usual: normally 130 print columns, which can fit
  1415. onto a traditional printer line.  You can set the width of the output
  1416. with the <samp><span class="option">-W </span><var>columns</var></samp> or <samp><span class="option">--width=</span><var>columns</var></samp>
  1417. option.  The output is split into two halves of equal width, separated by a
  1418. small gutter to mark differences; the right half is aligned to a tab
  1419. stop so that tabs line up.  Input lines that are too long to fit in half
  1420. of an output line are truncated for output.
  1421.  
  1422.    <p>The <samp><span class="option">--left-column</span></samp> option prints only the left column of two
  1423. common lines.  The <samp><span class="option">--suppress-common-lines</span></samp> option suppresses
  1424. common lines entirely.
  1425.  
  1426. <div class="node">
  1427. <p><hr>
  1428. <a name="Example-Side-by-Side"></a>
  1429. Previous: <a rel="previous" accesskey="p" href="#Side-by-Side-Format">Side by Side Format</a>,
  1430. Up: <a rel="up" accesskey="u" href="#Side-by-Side">Side by Side</a>
  1431.  
  1432. </div>
  1433.  
  1434. <h4 class="subsection">2.4.2 An Example of Side by Side Format</h4>
  1435.  
  1436. <p>Here is the output of the command `<samp><span class="samp">diff -y -W 72 lao tzu</span></samp>'
  1437. (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).
  1438.  
  1439. <pre class="example">     The Way that can be told of is n   <
  1440.      The name that can be named is no   <
  1441.      The Nameless is the origin of He        The Nameless is the origin of He
  1442.      The Named is the mother of all t   |    The named is the mother of all t
  1443.                                         >
  1444.      Therefore let there always be no        Therefore let there always be no
  1445.        so we may see their subtlety,           so we may see their subtlety,
  1446.      And let there always be being,          And let there always be being,
  1447.        so we may see their outcome.            so we may see their outcome.
  1448.      The two are the same,                   The two are the same,
  1449.      But after they are produced,            But after they are produced,
  1450.        they have different names.              they have different names.
  1451.                                         >    They both may be called deep and
  1452.                                         >    Deeper and more profound,
  1453.                                         >    The door of all subtleties!
  1454. </pre>
  1455.    <div class="node">
  1456. <p><hr>
  1457. <a name="Scripts"></a>
  1458. Next: <a rel="next" accesskey="n" href="#If_002dthen_002delse">If-then-else</a>,
  1459. Previous: <a rel="previous" accesskey="p" href="#Side-by-Side">Side by Side</a>,
  1460. Up: <a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>
  1461.  
  1462. </div>
  1463.  
  1464. <h3 class="section">2.5 Making Edit Scripts</h3>
  1465.  
  1466. <p><a name="index-script-output-formats-38"></a>
  1467. Several output modes produce command scripts for editing <var>from-file</var>
  1468. to produce <var>to-file</var>.
  1469.  
  1470. <ul class="menu">
  1471. <li><a accesskey="1" href="#ed-Scripts">ed Scripts</a>:  Using <samp><span class="command">diff</span></samp> to produce commands for <samp><span class="command">ed</span></samp>. 
  1472. <li><a accesskey="2" href="#Forward-ed">Forward ed</a>:  Making forward <samp><span class="command">ed</span></samp> scripts. 
  1473. <li><a accesskey="3" href="#RCS">RCS</a>:         A special <samp><span class="command">diff</span></samp> output format used by <span class="sc">rcs</span>. 
  1474. </ul>
  1475.  
  1476. <div class="node">
  1477. <p><hr>
  1478. <a name="ed-Scripts"></a>
  1479. Next: <a rel="next" accesskey="n" href="#Forward-ed">Forward ed</a>,
  1480. Up: <a rel="up" accesskey="u" href="#Scripts">Scripts</a>
  1481.  
  1482. </div>
  1483.  
  1484. <h4 class="subsection">2.5.1 <samp><span class="command">ed</span></samp> Scripts</h4>
  1485.  
  1486. <p><a name="index-g_t_0040command_007bed_007d-script-output-format-39"></a>
  1487. <samp><span class="command">diff</span></samp> can produce commands that direct the <samp><span class="command">ed</span></samp> text editor
  1488. to change the first file into the second file.  Long ago, this was the
  1489. only output mode that was suitable for editing one file into another
  1490. automatically; today, with <samp><span class="command">patch</span></samp>, it is almost obsolete.  Use the
  1491. <samp><span class="option">-e</span></samp> or <samp><span class="option">--ed</span></samp> option to select this output format.
  1492.  
  1493.    <p>Like the normal format (see <a href="#Normal">Normal</a>), this output format does not
  1494. show any context; unlike the normal format, it does not include the
  1495. information necessary to apply the diff in reverse (to produce the first
  1496. file if all you have is the second file and the diff).
  1497.  
  1498.    <p>If the file <samp><span class="file">d</span></samp> contains the output of `<samp><span class="samp">diff -e old new</span></samp>', then
  1499. the command `<samp><span class="samp">(cat d && echo w) | ed - old</span></samp>' edits <samp><span class="file">old</span></samp> to make
  1500. it a copy of <samp><span class="file">new</span></samp>.  More generally, if <samp><span class="file">d1</span></samp>, <samp><span class="file">d2</span></samp>,
  1501. <small class="dots">...</small>, <samp><span class="file">dN</span></samp> contain the outputs of `<samp><span class="samp">diff -e old new1</span></samp>',
  1502. `<samp><span class="samp">diff -e new1 new2</span></samp>', <small class="dots">...</small>, `<samp><span class="samp">diff -e newN-1 newN</span></samp>',
  1503. respectively, then the command `<samp><span class="samp">(cat d1 d2 ... dN && echo w) |
  1504. ed - old</span></samp>' edits <samp><span class="file">old</span></samp> to make it a copy of <samp><span class="file">newN</span></samp>.
  1505.  
  1506. <ul class="menu">
  1507. <li><a accesskey="1" href="#Detailed-ed">Detailed ed</a>:  A detailed description of <samp><span class="command">ed</span></samp> format. 
  1508. <li><a accesskey="2" href="#Example-ed">Example ed</a>:   A sample <samp><span class="command">ed</span></samp> script. 
  1509. </ul>
  1510.  
  1511. <div class="node">
  1512. <p><hr>
  1513. <a name="Detailed-ed"></a>
  1514. Next: <a rel="next" accesskey="n" href="#Example-ed">Example ed</a>,
  1515. Up: <a rel="up" accesskey="u" href="#ed-Scripts">ed Scripts</a>
  1516.  
  1517. </div>
  1518.  
  1519. <h5 class="subsubsection">2.5.1.1 Detailed Description of <samp><span class="command">ed</span></samp> Format</h5>
  1520.  
  1521. <p>The <samp><span class="command">ed</span></samp> output format consists of one or more hunks of
  1522. differences.  The changes closest to the ends of the files come first so
  1523. that commands that change the number of lines do not affect how
  1524. <samp><span class="command">ed</span></samp> interprets line numbers in succeeding commands.  <samp><span class="command">ed</span></samp>
  1525. format hunks look like this:
  1526.  
  1527. <pre class="example">     <var>change-command</var>
  1528.      <var>to-file-line</var>
  1529.      <var>to-file-line</var>...
  1530.      .
  1531. </pre>
  1532.    <p>Because <samp><span class="command">ed</span></samp> uses a single period on a line to indicate the end of
  1533. input, <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> protects lines of changes that contain a single
  1534. period on a line by writing two periods instead, then writing a
  1535. subsequent <samp><span class="command">ed</span></samp> command to change the two periods into one.  The
  1536. <samp><span class="command">ed</span></samp> format cannot represent an incomplete line, so if the second
  1537. file ends in a changed incomplete line, <samp><span class="command">diff</span></samp> reports an error and
  1538. then pretends that a newline was appended.
  1539.  
  1540.    <p>There are three types of change commands.  Each consists of a line
  1541. number or comma-separated range of lines in the first file and a single
  1542. character indicating the kind of change to make.  All line numbers are
  1543. the original line numbers in the file.  The types of change commands
  1544. are:
  1545.  
  1546.      <dl>
  1547. <dt>`<samp><var>l</var><span class="samp">a</span></samp>'<dd>Add text from the second file after line <var>l</var> in the first file.  For
  1548. example, `<samp><span class="samp">8a</span></samp>' means to add the following lines after line 8 of file
  1549. 1.
  1550.  
  1551.      <br><dt>`<samp><var>r</var><span class="samp">c</span></samp>'<dd>Replace the lines in range <var>r</var> in the first file with the following
  1552. lines.  Like a combined add and delete, but more compact.  For example,
  1553. `<samp><span class="samp">5,7c</span></samp>' means change lines 5–7 of file 1 to read as the text file
  1554. 2.
  1555.  
  1556.      <br><dt>`<samp><var>r</var><span class="samp">d</span></samp>'<dd>Delete the lines in range <var>r</var> from the first file.  For example,
  1557. `<samp><span class="samp">5,7d</span></samp>' means delete lines 5–7 of file 1. 
  1558. </dl>
  1559.  
  1560. <div class="node">
  1561. <p><hr>
  1562. <a name="Example-ed"></a>
  1563. Previous: <a rel="previous" accesskey="p" href="#Detailed-ed">Detailed ed</a>,
  1564. Up: <a rel="up" accesskey="u" href="#ed-Scripts">ed Scripts</a>
  1565.  
  1566. </div>
  1567.  
  1568. <h5 class="subsubsection">2.5.1.2 Example <samp><span class="command">ed</span></samp> Script</h5>
  1569.  
  1570. <p>Here is the output of `<samp><span class="samp">diff -e lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
  1571.  
  1572. <pre class="example">     11a
  1573.      They both may be called deep and profound.
  1574.      Deeper and more profound,
  1575.      The door of all subtleties!
  1576.      .
  1577.      4c
  1578.      The named is the mother of all things.
  1579.      
  1580.      .
  1581.      1,2d
  1582. </pre>
  1583.    <div class="node">
  1584. <p><hr>
  1585. <a name="Forward-ed"></a>
  1586. Next: <a rel="next" accesskey="n" href="#RCS">RCS</a>,
  1587. Previous: <a rel="previous" accesskey="p" href="#ed-Scripts">ed Scripts</a>,
  1588. Up: <a rel="up" accesskey="u" href="#Scripts">Scripts</a>
  1589.  
  1590. </div>
  1591.  
  1592. <h4 class="subsection">2.5.2 Forward <samp><span class="command">ed</span></samp> Scripts</h4>
  1593.  
  1594. <p><a name="index-forward-_0040command_007bed_007d-script-output-format-40"></a>
  1595. <samp><span class="command">diff</span></samp> can produce output that is like an <samp><span class="command">ed</span></samp> script, but
  1596. with hunks in forward (front to back) order.  The format of the commands
  1597. is also changed slightly: command characters precede the lines they
  1598. modify, spaces separate line numbers in ranges, and no attempt is made
  1599. to disambiguate hunk lines consisting of a single period.  Like
  1600. <samp><span class="command">ed</span></samp> format, forward <samp><span class="command">ed</span></samp> format cannot represent incomplete
  1601. lines.
  1602.  
  1603.    <p>Forward <samp><span class="command">ed</span></samp> format is not very useful, because neither <samp><span class="command">ed</span></samp>
  1604. nor <samp><span class="command">patch</span></samp> can apply diffs in this format.  It exists mainly for
  1605. compatibility with older versions of <samp><span class="command">diff</span></samp>.  Use the <samp><span class="option">-f</span></samp> or
  1606. <samp><span class="option">--forward-ed</span></samp> option to select it.
  1607.  
  1608. <div class="node">
  1609. <p><hr>
  1610. <a name="RCS"></a>
  1611. Previous: <a rel="previous" accesskey="p" href="#Forward-ed">Forward ed</a>,
  1612. Up: <a rel="up" accesskey="u" href="#Scripts">Scripts</a>
  1613.  
  1614. </div>
  1615.  
  1616. <h4 class="subsection">2.5.3 <span class="sc">rcs</span> Scripts</h4>
  1617.  
  1618. <p><a name="index-g_t_0040sc_007brcs_007d-script-output-format-41"></a>
  1619. The <span class="sc">rcs</span> output format is designed specifically for use by the Revision
  1620. Control System, which is a set of free programs used for organizing
  1621. different versions and systems of files.  Use the <samp><span class="option">-n</span></samp> or
  1622. <samp><span class="option">--rcs</span></samp> option to select this output format.  It is like the
  1623. forward <samp><span class="command">ed</span></samp> format (see <a href="#Forward-ed">Forward ed</a>), but it can represent
  1624. arbitrary changes to the contents of a file because it avoids the
  1625. forward <samp><span class="command">ed</span></samp> format's problems with lines consisting of a single
  1626. period and with incomplete lines.  Instead of ending text sections with
  1627. a line consisting of a single period, each command specifies the number
  1628. of lines it affects; a combination of the `<samp><span class="samp">a</span></samp>' and `<samp><span class="samp">d</span></samp>'
  1629. commands are used instead of `<samp><span class="samp">c</span></samp>'.  Also, if the second file ends
  1630. in a changed incomplete line, then the output also ends in an
  1631. incomplete line.
  1632.  
  1633.    <p>Here is the output of `<samp><span class="samp">diff -n lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
  1634.  
  1635. <pre class="example">     d1 2
  1636.      d4 1
  1637.      a4 2
  1638.      The named is the mother of all things.
  1639.      
  1640.      a11 3
  1641.      They both may be called deep and profound.
  1642.      Deeper and more profound,
  1643.      The door of all subtleties!
  1644. </pre>
  1645.    <div class="node">
  1646. <p><hr>
  1647. <a name="If-then-else"></a>
  1648. <a name="If_002dthen_002delse"></a>
  1649. Previous: <a rel="previous" accesskey="p" href="#Scripts">Scripts</a>,
  1650. Up: <a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>
  1651.  
  1652. </div>
  1653.  
  1654. <h3 class="section">2.6 Merging Files with If-then-else</h3>
  1655.  
  1656. <p><a name="index-merged-output-format-42"></a><a name="index-if_002dthen_002delse-output-format-43"></a><a name="index-C-if_002dthen_002delse-output-format-44"></a><a name="index-g_t_0040command_007bifdef_007d-output-format-45"></a>
  1657. You can use <samp><span class="command">diff</span></samp> to merge two files of C source code.  The output
  1658. of <samp><span class="command">diff</span></samp> in this format contains all the lines of both files. 
  1659. Lines common to both files are output just once; the differing parts are
  1660. separated by the C preprocessor directives <code>#ifdef </code><var>name</var> or
  1661. <code>#ifndef </code><var>name</var>, <code>#else</code>, and <code>#endif</code>.  When
  1662. compiling the output, you select which version to use by either defining
  1663. or leaving undefined the macro <var>name</var>.
  1664.  
  1665.    <p>To merge two files, use <samp><span class="command">diff</span></samp> with the <samp><span class="option">-D </span><var>name</var></samp> or
  1666. <samp><span class="option">--ifdef=</span><var>name</var></samp> option.  The argument <var>name</var> is the C
  1667. preprocessor identifier to use in the <code>#ifdef</code> and <code>#ifndef</code>
  1668. directives.
  1669.  
  1670.    <p>For example, if you change an instance of <code>wait (&s)</code> to
  1671. <code>waitpid (-1, &s, 0)</code> and then merge the old and new files with
  1672. the <samp><span class="option">--ifdef=HAVE_WAITPID</span></samp> option, then the affected part of your code
  1673. might look like this:
  1674.  
  1675. <pre class="example">         do {
  1676.      #ifndef HAVE_WAITPID
  1677.              if ((w = wait (&s)) < 0  &&  errno != EINTR)
  1678.      #else /* HAVE_WAITPID */
  1679.              if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
  1680.      #endif /* HAVE_WAITPID */
  1681.                  return w;
  1682.          } while (w != child);
  1683. </pre>
  1684.    <p>You can specify formats for languages other than C by using line group
  1685. formats and line formats, as described in the next sections.
  1686.  
  1687. <ul class="menu">
  1688. <li><a accesskey="1" href="#Line-Group-Formats">Line Group Formats</a>:     Formats for general if-then-else line groups. 
  1689. <li><a accesskey="2" href="#Line-Formats">Line Formats</a>:           Formats for each line in a line group. 
  1690. <li><a accesskey="3" href="#Detailed-If_002dthen_002delse">Detailed If-then-else</a>:  A detailed description of if-then-else format. 
  1691. <li><a accesskey="4" href="#Example-If_002dthen_002delse">Example If-then-else</a>:   Sample if-then-else format output. 
  1692. </ul>
  1693.  
  1694. <div class="node">
  1695. <p><hr>
  1696. <a name="Line-Group-Formats"></a>
  1697. Next: <a rel="next" accesskey="n" href="#Line-Formats">Line Formats</a>,
  1698. Up: <a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>
  1699.  
  1700. </div>
  1701.  
  1702. <h4 class="subsection">2.6.1 Line Group Formats</h4>
  1703.  
  1704. <p><a name="index-line-group-formats-46"></a><a name="index-formats-for-if_002dthen_002delse-line-groups-47"></a>
  1705. Line group formats let you specify formats suitable for many
  1706. applications that allow if-then-else input, including programming
  1707. languages and text formatting languages.  A line group format specifies
  1708. the output format for a contiguous group of similar lines.
  1709.  
  1710.    <p>For example, the following command compares the TeX files <samp><span class="file">old</span></samp>
  1711. and <samp><span class="file">new</span></samp>, and outputs a merged file in which old regions are
  1712. surrounded by `<samp><span class="samp">\begin{em}</span></samp>'-`<samp><span class="samp">\end{em}</span></samp>' lines, and new
  1713. regions are surrounded by `<samp><span class="samp">\begin{bf}</span></samp>'-`<samp><span class="samp">\end{bf}</span></samp>' lines.
  1714.  
  1715. <pre class="example">     diff \
  1716.         --old-group-format='\begin{em}
  1717.      %<\end{em}
  1718.      ' \
  1719.         --new-group-format='\begin{bf}
  1720.      %>\end{bf}
  1721.      ' \
  1722.         old new
  1723. </pre>
  1724.    <p>The following command is equivalent to the above example, but it is a
  1725. little more verbose, because it spells out the default line group formats.
  1726.  
  1727. <pre class="example">     diff \
  1728.         --old-group-format='\begin{em}
  1729.      %<\end{em}
  1730.      ' \
  1731.         --new-group-format='\begin{bf}
  1732.      %>\end{bf}
  1733.      ' \
  1734.         --unchanged-group-format='%=' \
  1735.         --changed-group-format='\begin{em}
  1736.      %<\end{em}
  1737.      \begin{bf}
  1738.      %>\end{bf}
  1739.      ' \
  1740.         old new
  1741. </pre>
  1742.    <p>Here is a more advanced example, which outputs a diff listing with
  1743. headers containing line numbers in a “plain English” style.
  1744.  
  1745. <pre class="example">     diff \
  1746.         --unchanged-group-format='' \
  1747.         --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
  1748.      %<' \
  1749.         --new-group-format='-------- %dN line%(N=1?:s) added after %de:
  1750.      %>' \
  1751.         --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
  1752.      %<-------- to:
  1753.      %>' \
  1754.         old new
  1755. </pre>
  1756.    <p>To specify a line group format, use <samp><span class="command">diff</span></samp> with one of the options
  1757. listed below.  You can specify up to four line group formats, one for
  1758. each kind of line group.  You should quote <var>format</var>, because it
  1759. typically contains shell metacharacters.
  1760.  
  1761.      <dl>
  1762. <dt><samp><span class="option">--old-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing only lines from the first file. 
  1763. The default old group format is the same as the changed group format if
  1764. it is specified; otherwise it is a format that outputs the line group as-is.
  1765.  
  1766.      <br><dt><samp><span class="option">--new-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing only lines from the second
  1767. file.  The default new group format is same as the changed group
  1768. format if it is specified; otherwise it is a format that outputs the
  1769. line group as-is.
  1770.  
  1771.      <br><dt><samp><span class="option">--changed-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing lines from both files.  The
  1772. default changed group format is the concatenation of the old and new
  1773. group formats.
  1774.  
  1775.      <br><dt><samp><span class="option">--unchanged-group-format=</span><var>format</var></samp><dd>These line groups contain lines common to both files.  The default
  1776. unchanged group format is a format that outputs the line group as-is. 
  1777. </dl>
  1778.  
  1779.    <p>In a line group format, ordinary characters represent themselves;
  1780. conversion specifications start with `<samp><span class="samp">%</span></samp>' and have one of the
  1781. following forms.
  1782.  
  1783.      <dl>
  1784. <dt>`<samp><span class="samp">%<</span></samp>'<dd>stands for the lines from the first file, including the trailing newline. 
  1785. Each line is formatted according to the old line format (see <a href="#Line-Formats">Line Formats</a>).
  1786.  
  1787.      <br><dt>`<samp><span class="samp">%></span></samp>'<dd>stands for the lines from the second file, including the trailing newline. 
  1788. Each line is formatted according to the new line format.
  1789.  
  1790.      <br><dt>`<samp><span class="samp">%=</span></samp>'<dd>stands for the lines common to both files, including the trailing newline. 
  1791. Each line is formatted according to the unchanged line format.
  1792.  
  1793.      <br><dt>`<samp><span class="samp">%%</span></samp>'<dd>stands for `<samp><span class="samp">%</span></samp>'.
  1794.  
  1795.      <br><dt>`<samp><span class="samp">%c'</span><var>C</var><span class="samp">'</span></samp>'<dd>where <var>C</var> is a single character, stands for <var>C</var>. 
  1796. <var>C</var> may not be a backslash or an apostrophe. 
  1797. For example, `<samp><span class="samp">%c':'</span></samp>' stands for a colon, even inside
  1798. the then-part of an if-then-else format, which a colon would
  1799. normally terminate.
  1800.  
  1801.      <br><dt>`<samp><span class="samp">%c'\</span><var>O</var><span class="samp">'</span></samp>'<dd>where <var>O</var> is a string of 1, 2, or 3 octal digits,
  1802. stands for the character with octal code <var>O</var>. 
  1803. For example, `<samp><span class="samp">%c'\0'</span></samp>' stands for a null character.
  1804.  
  1805.      <br><dt>`<samp><var>F</var><var>n</var></samp>'<dd>where <var>F</var> is a <code>printf</code> conversion specification and <var>n</var> is one
  1806. of the following letters, stands for <var>n</var>'s value formatted with <var>F</var>.
  1807.  
  1808.           <dl>
  1809. <dt>`<samp><span class="samp">e</span></samp>'<dd>The line number of the line just before the group in the old file.
  1810.  
  1811.           <br><dt>`<samp><span class="samp">f</span></samp>'<dd>The line number of the first line in the group in the old file;
  1812. equals <var>e</var> + 1.
  1813.  
  1814.           <br><dt>`<samp><span class="samp">l</span></samp>'<dd>The line number of the last line in the group in the old file.
  1815.  
  1816.           <br><dt>`<samp><span class="samp">m</span></samp>'<dd>The line number of the line just after the group in the old file;
  1817. equals <var>l</var> + 1.
  1818.  
  1819.           <br><dt>`<samp><span class="samp">n</span></samp>'<dd>The number of lines in the group in the old file; equals <var>l</var> - <var>f</var> + 1.
  1820.  
  1821.           <br><dt>`<samp><span class="samp">E, F, L, M, N</span></samp>'<dd>Likewise, for lines in the new file.
  1822.  
  1823.      </dl>
  1824.  
  1825.      <p><a name="index-LC_005fNUMERIC-48"></a>The <code>printf</code> conversion specification can be `<samp><span class="samp">%d</span></samp>',
  1826. `<samp><span class="samp">%o</span></samp>', `<samp><span class="samp">%x</span></samp>', or `<samp><span class="samp">%X</span></samp>', specifying decimal, octal,
  1827. lower case hexadecimal, or upper case hexadecimal output
  1828. respectively.  After the `<samp><span class="samp">%</span></samp>' the following options can appear in
  1829. sequence: a series of zero or more flags; an integer
  1830. specifying the minimum field width; and a period followed by an
  1831. optional integer specifying the minimum number of digits. 
  1832. The flags are `<samp><span class="samp">-</span></samp>' for left-justification, `<samp><span class="samp">'</span></samp>' for separating
  1833. the digit into groups as specified by the <samp><span class="env">LC_NUMERIC</span></samp> locale category,
  1834. and `<samp><span class="samp">0</span></samp>' for padding with zeros instead of spaces. 
  1835. For example, `<samp><span class="samp">%5dN</span></samp>' prints the number of new lines in the group
  1836. in a field of width 5 characters, using the <code>printf</code> format <code>"%5d"</code>.
  1837.  
  1838.      <br><dt>`<samp><span class="samp">(</span><var>A</var><span class="samp">=</span><var>B</var><span class="samp">?</span><var>T</var><span class="samp">:</span><var>E</var><span class="samp">)</span></samp>'<dd>If <var>A</var> equals <var>B</var> then <var>T</var> else <var>E</var>. 
  1839. <var>A</var> and <var>B</var> are each either a decimal constant
  1840. or a single letter interpreted as above. 
  1841. This format spec is equivalent to <var>T</var> if
  1842. <var>A</var>'s value equals <var>B</var>'s; otherwise it is equivalent to <var>E</var>.
  1843.  
  1844.      <p>For example, `<samp><span class="samp">%(N=0?no:%dN) line%(N=1?:s)</span></samp>' is equivalent to
  1845. `<samp><span class="samp">no lines</span></samp>' if <var>N</var> (the number of lines in the group in the the
  1846. new file) is 0, to `<samp><span class="samp">1 line</span></samp>' if <var>N</var> is 1, and to `<samp><span class="samp">%dN lines</span></samp>'
  1847. otherwise. 
  1848. </dl>
  1849.  
  1850. <div class="node">
  1851. <p><hr>
  1852. <a name="Line-Formats"></a>
  1853. Next: <a rel="next" accesskey="n" href="#Detailed-If_002dthen_002delse">Detailed If-then-else</a>,
  1854. Previous: <a rel="previous" accesskey="p" href="#Line-Group-Formats">Line Group Formats</a>,
  1855. Up: <a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>
  1856.  
  1857. </div>
  1858.  
  1859. <h4 class="subsection">2.6.2 Line Formats</h4>
  1860.  
  1861. <p><a name="index-line-formats-49"></a>
  1862. Line formats control how each line taken from an input file is
  1863. output as part of a line group in if-then-else format.
  1864.  
  1865.    <p>For example, the following command outputs text with a one-character
  1866. change indicator to the left of the text.  The first character of output
  1867. is `<samp><span class="samp">-</span></samp>' for deleted lines, `<samp><span class="samp">|</span></samp>' for added lines, and a space for
  1868. unchanged lines.  The formats contain newline characters where newlines
  1869. are desired on output.
  1870.  
  1871. <pre class="example">     diff \
  1872.         --old-line-format='-%l
  1873.      ' \
  1874.         --new-line-format='|%l
  1875.      ' \
  1876.         --unchanged-line-format=' %l
  1877.      ' \
  1878.         old new
  1879. </pre>
  1880.    <p>To specify a line format, use one of the following options.  You should
  1881. quote <var>format</var>, since it often contains shell metacharacters.
  1882.  
  1883.      <dl>
  1884. <dt><samp><span class="option">--old-line-format=</span><var>format</var></samp><dd>formats lines just from the first file.
  1885.  
  1886.      <br><dt><samp><span class="option">--new-line-format=</span><var>format</var></samp><dd>formats lines just from the second file.
  1887.  
  1888.      <br><dt><samp><span class="option">--unchanged-line-format=</span><var>format</var></samp><dd>formats lines common to both files.
  1889.  
  1890.      <br><dt><samp><span class="option">--line-format=</span><var>format</var></samp><dd>formats all lines; in effect, it sets all three above options simultaneously. 
  1891. </dl>
  1892.  
  1893.    <p>In a line format, ordinary characters represent themselves;
  1894. conversion specifications start with `<samp><span class="samp">%</span></samp>' and have one of the
  1895. following forms.
  1896.  
  1897.      <dl>
  1898. <dt>`<samp><span class="samp">%l</span></samp>'<dd>stands for the contents of the line, not counting its trailing
  1899. newline (if any).  This format ignores whether the line is incomplete;
  1900. See <a href="#Incomplete-Lines">Incomplete Lines</a>.
  1901.  
  1902.      <br><dt>`<samp><span class="samp">%L</span></samp>'<dd>stands for the contents of the line, including its trailing newline
  1903. (if any).  If a line is incomplete, this format preserves its
  1904. incompleteness.
  1905.  
  1906.      <br><dt>`<samp><span class="samp">%%</span></samp>'<dd>stands for `<samp><span class="samp">%</span></samp>'.
  1907.  
  1908.      <br><dt>`<samp><span class="samp">%c'</span><var>C</var><span class="samp">'</span></samp>'<dd>where <var>C</var> is a single character, stands for <var>C</var>. 
  1909. <var>C</var> may not be a backslash or an apostrophe. 
  1910. For example, `<samp><span class="samp">%c':'</span></samp>' stands for a colon.
  1911.  
  1912.      <br><dt>`<samp><span class="samp">%c'\</span><var>O</var><span class="samp">'</span></samp>'<dd>where <var>O</var> is a string of 1, 2, or 3 octal digits,
  1913. stands for the character with octal code <var>O</var>. 
  1914. For example, `<samp><span class="samp">%c'\0'</span></samp>' stands for a null character.
  1915.  
  1916.      <br><dt>`<samp><var>F</var><span class="samp">n</span></samp>'<dd>where <var>F</var> is a <code>printf</code> conversion specification,
  1917. stands for the line number formatted with <var>F</var>. 
  1918. For example, `<samp><span class="samp">%.5dn</span></samp>' prints the line number using the
  1919. <code>printf</code> format <code>"%.5d"</code>.  See <a href="#Line-Group-Formats">Line Group Formats</a>, for
  1920. more about printf conversion specifications.
  1921.  
  1922.    </dl>
  1923.  
  1924.    <p>The default line format is `<samp><span class="samp">%l</span></samp>' followed by a newline character.
  1925.  
  1926.    <p>If the input contains tab characters and it is important that they line
  1927. up on output, you should ensure that `<samp><span class="samp">%l</span></samp>' or `<samp><span class="samp">%L</span></samp>' in a line
  1928. format is just after a tab stop (e.g. by preceding `<samp><span class="samp">%l</span></samp>' or
  1929. `<samp><span class="samp">%L</span></samp>' with a tab character), or you should use the <samp><span class="option">-t</span></samp> or
  1930. <samp><span class="option">--expand-tabs</span></samp> option.
  1931.  
  1932.    <p>Taken together, the line and line group formats let you specify many
  1933. different formats.  For example, the following command uses a format
  1934. similar to normal <samp><span class="command">diff</span></samp> format.  You can tailor this command
  1935. to get fine control over <samp><span class="command">diff</span></samp> output.
  1936.  
  1937. <pre class="example">     diff \
  1938.         --old-line-format='< %l
  1939.      ' \
  1940.         --new-line-format='> %l
  1941.      ' \
  1942.         --old-group-format='%df%(f=l?:,%dl)d%dE
  1943.      %<' \
  1944.         --new-group-format='%dea%dF%(F=L?:,%dL)
  1945.      %>' \
  1946.         --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
  1947.      %<---
  1948.      %>' \
  1949.         --unchanged-group-format='' \
  1950.         old new
  1951. </pre>
  1952.    <div class="node">
  1953. <p><hr>
  1954. <a name="Detailed-If-then-else"></a>
  1955. <a name="Detailed-If_002dthen_002delse"></a>
  1956. Next: <a rel="next" accesskey="n" href="#Example-If_002dthen_002delse">Example If-then-else</a>,
  1957. Previous: <a rel="previous" accesskey="p" href="#Line-Formats">Line Formats</a>,
  1958. Up: <a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>
  1959.  
  1960. </div>
  1961.  
  1962. <h4 class="subsection">2.6.3 Detailed Description of If-then-else Format</h4>
  1963.  
  1964. <p>For lines common to both files, <samp><span class="command">diff</span></samp> uses the unchanged line
  1965. group format.  For each hunk of differences in the merged output
  1966. format, if the hunk contains only lines from the first file,
  1967. <samp><span class="command">diff</span></samp> uses the old line group format; if the hunk contains only
  1968. lines from the second file, <samp><span class="command">diff</span></samp> uses the new group format;
  1969. otherwise, <samp><span class="command">diff</span></samp> uses the changed group format.
  1970.  
  1971.    <p>The old, new, and unchanged line formats specify the output format of
  1972. lines from the first file, lines from the second file, and lines common
  1973. to both files, respectively.
  1974.  
  1975.    <p>The option <samp><span class="option">--ifdef=</span><var>name</var></samp> is equivalent to
  1976. the following sequence of options using shell syntax:
  1977.  
  1978. <pre class="example">     --old-group-format='#ifndef <var>name</var>
  1979.      %<#endif /* ! <var>name</var> */
  1980.      ' \
  1981.      --new-group-format='#ifdef <var>name</var>
  1982.      %>#endif /* <var>name</var> */
  1983.      ' \
  1984.      --unchanged-group-format='%=' \
  1985.      --changed-group-format='#ifndef <var>name</var>
  1986.      %<#else /* <var>name</var> */
  1987.      %>#endif /* <var>name</var> */
  1988.      '
  1989. </pre>
  1990.    <p>You should carefully check the <samp><span class="command">diff</span></samp> output for proper nesting. 
  1991. For example, when using the <samp><span class="option">-D </span><var>name</var></samp> or
  1992. <samp><span class="option">--ifdef=</span><var>name</var></samp> option, you should check that if the
  1993. differing lines contain any of the C preprocessor directives
  1994. `<samp><span class="samp">#ifdef</span></samp>', `<samp><span class="samp">#ifndef</span></samp>', `<samp><span class="samp">#else</span></samp>', `<samp><span class="samp">#elif</span></samp>', or
  1995. `<samp><span class="samp">#endif</span></samp>', they are nested properly and match.  If they don't, you
  1996. must make corrections manually.  It is a good idea to carefully check
  1997. the resulting code anyway to make sure that it really does what you
  1998. want it to; depending on how the input files were produced, the output
  1999. might contain duplicate or otherwise incorrect code.
  2000.  
  2001.    <p>The <samp><span class="command">patch</span></samp> <samp><span class="option">-D </span><var>name</var></samp> option behaves like
  2002. the <samp><span class="command">diff</span></samp> <samp><span class="option">-D </span><var>name</var></samp> option, except it operates on
  2003. a file and a diff to produce a merged file; See <a href="#patch-Options">patch Options</a>.
  2004.  
  2005. <div class="node">
  2006. <p><hr>
  2007. <a name="Example-If-then-else"></a>
  2008. <a name="Example-If_002dthen_002delse"></a>
  2009. Previous: <a rel="previous" accesskey="p" href="#Detailed-If_002dthen_002delse">Detailed If-then-else</a>,
  2010. Up: <a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>
  2011.  
  2012. </div>
  2013.  
  2014. <h4 class="subsection">2.6.4 An Example of If-then-else Format</h4>
  2015.  
  2016. <p>Here is the output of `<samp><span class="samp">diff -DTWO lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
  2017.  
  2018. <pre class="example">     #ifndef TWO
  2019.      The Way that can be told of is not the eternal Way;
  2020.      The name that can be named is not the eternal name.
  2021.      #endif /* ! TWO */
  2022.      The Nameless is the origin of Heaven and Earth;
  2023.      #ifndef TWO
  2024.      The Named is the mother of all things.
  2025.      #else /* TWO */
  2026.      The named is the mother of all things.
  2027.      
  2028.      #endif /* TWO */
  2029.      Therefore let there always be non-being,
  2030.        so we may see their subtlety,
  2031.      And let there always be being,
  2032.        so we may see their outcome.
  2033.      The two are the same,
  2034.      But after they are produced,
  2035.        they have different names.
  2036.      #ifdef TWO
  2037.      They both may be called deep and profound.
  2038.      Deeper and more profound,
  2039.      The door of all subtleties!
  2040.      #endif /* TWO */
  2041. </pre>
  2042.    <div class="node">
  2043. <p><hr>
  2044. <a name="Incomplete-Lines"></a>
  2045. Next: <a rel="next" accesskey="n" href="#Comparing-Directories">Comparing Directories</a>,
  2046. Previous: <a rel="previous" accesskey="p" href="#Output-Formats">Output Formats</a>,
  2047. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2048.  
  2049. </div>
  2050.  
  2051. <h2 class="chapter">3 Incomplete Lines</h2>
  2052.  
  2053. <p><a name="index-incomplete-lines-50"></a><a name="index-full-lines-51"></a><a name="index-newline-treatment-by-_0040command_007bdiff_007d-52"></a>
  2054. When an input file ends in a non-newline character, its last line is
  2055. called an <dfn>incomplete line</dfn> because its last character is not a
  2056. newline.  All other lines are called <dfn>full lines</dfn> and end in a
  2057. newline character.  Incomplete lines do not match full lines unless
  2058. differences in white space are ignored (see <a href="#White-Space">White Space</a>).
  2059.  
  2060.    <p>An incomplete line is normally distinguished on output from a full line
  2061. by a following line that starts with `<samp><span class="samp">\</span></samp>'.  However, the <span class="sc">rcs</span> format
  2062. (see <a href="#RCS">RCS</a>) outputs the incomplete line as-is, without any trailing
  2063. newline or following line.  The side by side format normally represents
  2064. incomplete lines as-is, but in some cases uses a `<samp><span class="samp">\</span></samp>' or `<samp><span class="samp">/</span></samp>'
  2065. gutter marker; See <a href="#Side-by-Side">Side by Side</a>.  The if-then-else line format
  2066. preserves a line's incompleteness with `<samp><span class="samp">%L</span></samp>', and discards the
  2067. newline with `<samp><span class="samp">%l</span></samp>'; See <a href="#Line-Formats">Line Formats</a>.  Finally, with the
  2068. <samp><span class="command">ed</span></samp> and forward <samp><span class="command">ed</span></samp> output formats (see <a href="#Output-Formats">Output Formats</a>)
  2069. <samp><span class="command">diff</span></samp> cannot represent an incomplete line, so it pretends there
  2070. was a newline and reports an error.
  2071.  
  2072.    <p>For example, suppose <samp><span class="file">F</span></samp> and <samp><span class="file">G</span></samp> are one-byte files that
  2073. contain just `<samp><span class="samp">f</span></samp>' and `<samp><span class="samp">g</span></samp>', respectively.  Then `<samp><span class="samp">diff F G</span></samp>'
  2074. outputs
  2075.  
  2076. <pre class="example">     1c1
  2077.      < f
  2078.      \ No newline at end of file
  2079.      ---
  2080.      > g
  2081.      \ No newline at end of file
  2082. </pre>
  2083.    <p class="noindent">(The exact message may differ in non-English locales.) 
  2084. `<samp><span class="samp">diff -n F G</span></samp>' outputs the following without a trailing newline:
  2085.  
  2086. <pre class="example">     d1 1
  2087.      a1 1
  2088.      g
  2089. </pre>
  2090.    <p class="noindent">`<samp><span class="samp">diff -e F G</span></samp>' reports two errors and outputs the following:
  2091.  
  2092. <pre class="example">     1c
  2093.      g
  2094.      .
  2095. </pre>
  2096.    <div class="node">
  2097. <p><hr>
  2098. <a name="Comparing-Directories"></a>
  2099. Next: <a rel="next" accesskey="n" href="#Adjusting-Output">Adjusting Output</a>,
  2100. Previous: <a rel="previous" accesskey="p" href="#Incomplete-Lines">Incomplete Lines</a>,
  2101. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2102.  
  2103. </div>
  2104.  
  2105. <h2 class="chapter">4 Comparing Directories</h2>
  2106.  
  2107. <p><a name="index-LC_005fCOLLATE-53"></a>You can use <samp><span class="command">diff</span></samp> to compare some or all of the files in two
  2108. directory trees.  When both file name arguments to <samp><span class="command">diff</span></samp> are
  2109. directories, it compares each file that is contained in both
  2110. directories, examining file names in alphabetical order as specified by
  2111. the <samp><span class="env">LC_COLLATE</span></samp> locale category.  Normally
  2112. <samp><span class="command">diff</span></samp> is silent about pairs of files that contain no differences,
  2113. but if you use the <samp><span class="option">-s</span></samp> or <samp><span class="option">--report-identical-files</span></samp> option,
  2114. it reports pairs of identical files.  Normally <samp><span class="command">diff</span></samp> reports
  2115. subdirectories common to both directories without comparing
  2116. subdirectories' files, but if you use the <samp><span class="option">-r</span></samp> or
  2117. <samp><span class="option">--recursive</span></samp> option, it compares every corresponding pair of files
  2118. in the directory trees, as many levels deep as they go.
  2119.  
  2120.    <p>For file names that are in only one of the directories, <samp><span class="command">diff</span></samp>
  2121. normally does not show the contents of the file that exists; it reports
  2122. only that the file exists in that directory and not in the other.  You
  2123. can make <samp><span class="command">diff</span></samp> act as though the file existed but was empty in the
  2124. other directory, so that it outputs the entire contents of the file that
  2125. actually exists.  (It is output as either an insertion or a
  2126. deletion, depending on whether it is in the first or the second
  2127. directory given.)  To do this, use the <samp><span class="option">-N</span></samp> or <samp><span class="option">--new-file</span></samp>
  2128. option.
  2129.  
  2130.    <p>If the older directory contains one or more large files that are not in
  2131. the newer directory, you can make the patch smaller by using the
  2132. <samp><span class="option">--unidirectional-new-file</span></samp> option instead of <samp><span class="option">-N</span></samp>. 
  2133. This option is like <samp><span class="option">-N</span></samp> except that it only inserts the contents
  2134. of files that appear in the second directory but not the first (that is,
  2135. files that were added).  At the top of the patch, write instructions for
  2136. the user applying the patch to remove the files that were deleted before
  2137. applying the patch.  See <a href="#Making-Patches">Making Patches</a>, for more discussion of
  2138. making patches for distribution.
  2139.  
  2140.    <p>To ignore some files while comparing directories, use the <samp><span class="option">-x
  2141. </span><var>pattern</var></samp> or <samp><span class="option">--exclude=</span><var>pattern</var></samp> option.  This option
  2142. ignores any files or subdirectories whose base names match the shell
  2143. pattern <var>pattern</var>.  Unlike in the shell, a period at the start of
  2144. the base of a file name matches a wildcard at the start of a pattern. 
  2145. You should enclose <var>pattern</var> in quotes so that the shell does not
  2146. expand it.  For example, the option <samp><span class="option">-x '*.[ao]'</span></samp> ignores any file
  2147. whose name ends with `<samp><span class="samp">.a</span></samp>' or `<samp><span class="samp">.o</span></samp>'.
  2148.  
  2149.    <p>This option accumulates if you specify it more than once.  For example,
  2150. using the options <samp><span class="option">-x 'RCS' -x '*,v'</span></samp> ignores any file or
  2151. subdirectory whose base name is `<samp><span class="samp">RCS</span></samp>' or ends with `<samp><span class="samp">,v</span></samp>'.
  2152.  
  2153.    <p>If you need to give this option many times, you can instead put the
  2154. patterns in a file, one pattern per line, and use the <samp><span class="option">-X
  2155. </span><var>file</var></samp> or <samp><span class="option">--exclude-from=</span><var>file</var></samp> option.
  2156.  
  2157.    <p>If you have been comparing two directories and stopped partway through,
  2158. later you might want to continue where you left off.  You can do this by
  2159. using the <samp><span class="option">-S </span><var>file</var></samp> or <samp><span class="option">--starting-file=</span><var>file</var></samp>
  2160. option.  This compares only the file <var>file</var> and all alphabetically
  2161. later files in the topmost directory level.
  2162.  
  2163.    <p>If two directories differ only in that file names are lower case in
  2164. one directory and upper case in the upper, <samp><span class="command">diff</span></samp> normally
  2165. reports many differences because it compares file names in a
  2166. case sensitive way.  With the <samp><span class="option">--ignore-file-name-case</span></samp> option,
  2167. <samp><span class="command">diff</span></samp> ignores case differences in file names, so that for example
  2168. the contents of the file <samp><span class="file">Tao</span></samp> in one directory are compared to
  2169. the contents of the file <samp><span class="file">TAO</span></samp> in the other.  The
  2170. <samp><span class="option">--no-ignore-file-name-case</span></samp> option cancels the effect of the
  2171. <samp><span class="option">--ignore-file-name-case</span></samp> option, reverting to the default
  2172. behavior.
  2173.  
  2174.    <p>If an <samp><span class="option">-x </span><var>pattern</var></samp>, <samp><span class="option">--exclude=</span><var>pattern</var></samp>,
  2175. <samp><span class="option">-X </span><var>file</var></samp>, or <samp><span class="option">--exclude-from=</span><var>file</var></samp> option
  2176. is specified while the <samp><span class="option">--ignore-file-name-case</span></samp> option is in
  2177. effect, case is ignored when excluding file names matching the
  2178. specified patterns.
  2179.  
  2180. <div class="node">
  2181. <p><hr>
  2182. <a name="Adjusting-Output"></a>
  2183. Next: <a rel="next" accesskey="n" href="#diff-Performance">diff Performance</a>,
  2184. Previous: <a rel="previous" accesskey="p" href="#Comparing-Directories">Comparing Directories</a>,
  2185. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2186.  
  2187. </div>
  2188.  
  2189. <h2 class="chapter">5 Making <samp><span class="command">diff</span></samp> Output Prettier</h2>
  2190.  
  2191. <p><samp><span class="command">diff</span></samp> provides several ways to adjust the appearance of its output. 
  2192. These adjustments can be applied to any output format.
  2193.  
  2194. <ul class="menu">
  2195. <li><a accesskey="1" href="#Tabs">Tabs</a>:        Preserving the alignment of tab stops. 
  2196. <li><a accesskey="2" href="#Pagination">Pagination</a>:  Page numbering and time-stamping <samp><span class="command">diff</span></samp> output. 
  2197. </ul>
  2198.  
  2199. <div class="node">
  2200. <p><hr>
  2201. <a name="Tabs"></a>
  2202. Next: <a rel="next" accesskey="n" href="#Pagination">Pagination</a>,
  2203. Up: <a rel="up" accesskey="u" href="#Adjusting-Output">Adjusting Output</a>
  2204.  
  2205. </div>
  2206.  
  2207. <h3 class="section">5.1 Preserving Tab Stop Alignment</h3>
  2208.  
  2209. <p><a name="index-tab-stop-alignment-54"></a><a name="index-aligning-tab-stops-55"></a>
  2210. The lines of text in some of the <samp><span class="command">diff</span></samp> output formats are preceded
  2211. by one or two characters that indicate whether the text is inserted,
  2212. deleted, or changed.  The addition of those characters can cause tabs to
  2213. move to the next tab stop, throwing off the alignment of columns in the
  2214. line.  <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> provides two ways to make tab-aligned columns
  2215. line up correctly.
  2216.  
  2217.    <p>The first way is to have <samp><span class="command">diff</span></samp> convert all tabs into the correct
  2218. number of spaces before outputting them; select this method with the
  2219. <samp><span class="option">-t</span></samp> or <samp><span class="option">--expand-tabs</span></samp> option.  <samp><span class="command">diff</span></samp> assumes that
  2220. tab stops are set every 8 print columns.  To use this form of output with
  2221. <samp><span class="command">patch</span></samp>, you must give <samp><span class="command">patch</span></samp> the <samp><span class="option">-l</span></samp> or
  2222. <samp><span class="option">--ignore-white-space</span></samp> option (see <a href="#Changed-White-Space">Changed White Space</a>, for more
  2223. information).
  2224.  
  2225.    <p>The other method for making tabs line up correctly is to add a tab
  2226. character instead of a space after the indicator character at the
  2227. beginning of the line.  This ensures that all following tab characters
  2228. are in the same position relative to tab stops that they were in the
  2229. original files, so that the output is aligned correctly.  Its
  2230. disadvantage is that it can make long lines too long to fit on one line
  2231. of the screen or the paper.  It also does not work with the unified
  2232. output format, which does not have a space character after the change
  2233. type indicator character.  Select this method with the <samp><span class="option">-T</span></samp> or
  2234. <samp><span class="option">--initial-tab</span></samp> option.
  2235.  
  2236. <div class="node">
  2237. <p><hr>
  2238. <a name="Pagination"></a>
  2239. Previous: <a rel="previous" accesskey="p" href="#Tabs">Tabs</a>,
  2240. Up: <a rel="up" accesskey="u" href="#Adjusting-Output">Adjusting Output</a>
  2241.  
  2242. </div>
  2243.  
  2244. <h3 class="section">5.2 Paginating <samp><span class="command">diff</span></samp> Output</h3>
  2245.  
  2246. <p><a name="index-paginating-_0040command_007bdiff_007d-output-56"></a>
  2247. It can be convenient to have long output page-numbered and time-stamped. 
  2248. The <samp><span class="option">-l</span></samp> and <samp><span class="option">--paginate</span></samp> options do this by sending the
  2249. <samp><span class="command">diff</span></samp> output through the <samp><span class="command">pr</span></samp> program.  Here is what the page
  2250. header might look like for `<samp><span class="samp">diff -lc lao tzu</span></samp>':
  2251.  
  2252. <pre class="example">     2002-02-22 14:20                 diff -lc lao tzu                 Page 1
  2253. </pre>
  2254.    <div class="node">
  2255. <p><hr>
  2256. <a name="diff-Performance"></a>
  2257. Next: <a rel="next" accesskey="n" href="#Comparing-Three-Files">Comparing Three Files</a>,
  2258. Previous: <a rel="previous" accesskey="p" href="#Adjusting-Output">Adjusting Output</a>,
  2259. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2260.  
  2261. </div>
  2262.  
  2263. <h2 class="chapter">6 <samp><span class="command">diff</span></samp> Performance Tradeoffs</h2>
  2264.  
  2265. <p><a name="index-performance-of-_0040command_007bdiff_007d-57"></a>
  2266. <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> runs quite efficiently; however, in some circumstances
  2267. you can cause it to run faster or produce a more compact set of changes.
  2268.  
  2269.    <p>One way to improve <samp><span class="command">diff</span></samp> performance is to use hard or
  2270. symbolic links to files instead of copies.  This improves performance
  2271. because <samp><span class="command">diff</span></samp> normally does not need to read two hard or
  2272. symbolic links to the same file, since their contents must be
  2273. identical.  For example, suppose you copy a large directory hierarchy,
  2274. make a few changes to the copy, and then often use `<samp><span class="samp">diff -r</span></samp>' to
  2275. compare the original to the copy.  If the original files are
  2276. read-only, you can greatly improve performance by creating the copy
  2277. using hard or symbolic links (e.g., with <span class="sc">gnu</span> `<samp><span class="samp">cp -lR</span></samp>' or
  2278. `<samp><span class="samp">cp -sR</span></samp>').  Before editing a file in the copy for the first time,
  2279. you should break the link and replace it with a regular copy.
  2280.  
  2281.    <p>You can also affect the performance of <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> by
  2282. giving it options that change the way it compares files. 
  2283. Performance has more than one dimension.  These options improve one
  2284. aspect of performance at the cost of another, or they improve
  2285. performance in some cases while hurting it in others.
  2286.  
  2287.    <p>The way that <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> determines which lines have changed always
  2288. comes up with a near-minimal set of differences.  Usually it is good
  2289. enough for practical purposes.  If the <samp><span class="command">diff</span></samp> output is large, you
  2290. might want <samp><span class="command">diff</span></samp> to use a modified algorithm that sometimes
  2291. produces a smaller set of differences.  The <samp><span class="option">-d</span></samp> or
  2292. <samp><span class="option">--minimal</span></samp> option does this; however, it can also cause
  2293. <samp><span class="command">diff</span></samp> to run more slowly than usual, so it is not the default
  2294. behavior.
  2295.  
  2296.    <p>When the files you are comparing are large and have small groups of
  2297. changes scattered throughout them, you can use the
  2298. <samp><span class="option">--speed-large-files</span></samp> option to make a different modification to
  2299. the algorithm that <samp><span class="command">diff</span></samp> uses.  If the input files have a constant
  2300. small density of changes, this option speeds up the comparisons without
  2301. changing the output.  If not, <samp><span class="command">diff</span></samp> might produce a larger set of
  2302. differences; however, the output will still be correct.
  2303.  
  2304.    <p>Normally <samp><span class="command">diff</span></samp> discards the prefix and suffix that is common to
  2305. both files before it attempts to find a minimal set of differences. 
  2306. This makes <samp><span class="command">diff</span></samp> run faster, but occasionally it may produce
  2307. non-minimal output.  The <samp><span class="option">--horizon-lines=</span><var>lines</var></samp> option
  2308. prevents <samp><span class="command">diff</span></samp> from discarding the last <var>lines</var> lines of the
  2309. prefix and the first <var>lines</var> lines of the suffix.  This gives
  2310. <samp><span class="command">diff</span></samp> further opportunities to find a minimal output.
  2311.  
  2312.    <p>Suppose a run of changed lines includes a sequence of lines at one end
  2313. and there is an identical sequence of lines just outside the other end. 
  2314. The <samp><span class="command">diff</span></samp> command is free to choose which identical sequence is
  2315. included in the hunk.  In this case, <samp><span class="command">diff</span></samp> normally shifts the
  2316. hunk's boundaries when this merges adjacent hunks, or shifts a hunk's
  2317. lines towards the end of the file.  Merging hunks can make the output
  2318. look nicer in some cases.
  2319.  
  2320. <div class="node">
  2321. <p><hr>
  2322. <a name="Comparing-Three-Files"></a>
  2323. Next: <a rel="next" accesskey="n" href="#diff3-Merging">diff3 Merging</a>,
  2324. Previous: <a rel="previous" accesskey="p" href="#diff-Performance">diff Performance</a>,
  2325. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2326.  
  2327. </div>
  2328.  
  2329. <h2 class="chapter">7 Comparing Three Files</h2>
  2330.  
  2331. <p><a name="index-comparing-three-files-58"></a><a name="index-format-of-_0040command_007bdiff3_007d-output-59"></a>
  2332. Use the program <samp><span class="command">diff3</span></samp> to compare three files and show any
  2333. differences among them.  (<samp><span class="command">diff3</span></samp> can also merge files; see
  2334. <a href="#diff3-Merging">diff3 Merging</a>).
  2335.  
  2336.    <p>The “normal” <samp><span class="command">diff3</span></samp> output format shows each hunk of
  2337. differences without surrounding context.  Hunks are labeled depending
  2338. on whether they are two-way or three-way, and lines are annotated by
  2339. their location in the input files.
  2340.  
  2341.    <p>See <a href="#Invoking-diff3">Invoking diff3</a>, for more information on how to run <samp><span class="command">diff3</span></samp>.
  2342.  
  2343. <ul class="menu">
  2344. <li><a accesskey="1" href="#Sample-diff3-Input">Sample diff3 Input</a>:     Sample <samp><span class="command">diff3</span></samp> input for examples. 
  2345. <li><a accesskey="2" href="#Detailed-diff3-Normal">Detailed diff3 Normal</a>:  A detailed description of normal output format. 
  2346. <li><a accesskey="3" href="#diff3-Hunks">diff3 Hunks</a>:            The format of normal output format. 
  2347. <li><a accesskey="4" href="#Example-diff3-Normal">Example diff3 Normal</a>:   Sample output in the normal format. 
  2348. </ul>
  2349.  
  2350. <div class="node">
  2351. <p><hr>
  2352. <a name="Sample-diff3-Input"></a>
  2353. Next: <a rel="next" accesskey="n" href="#Detailed-diff3-Normal">Detailed diff3 Normal</a>,
  2354. Up: <a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>
  2355.  
  2356. </div>
  2357.  
  2358. <h3 class="section">7.1 A Third Sample Input File</h3>
  2359.  
  2360. <p><a name="index-g_t_0040command_007bdiff3_007d-sample-input-60"></a><a name="index-sample-input-for-_0040command_007bdiff3_007d-61"></a>
  2361. Here is a third sample file that will be used in examples to illustrate
  2362. the output of <samp><span class="command">diff3</span></samp> and how various options can change it.  The
  2363. first two files are the same that we used for <samp><span class="command">diff</span></samp> (see <a href="#Sample-diff-Input">Sample diff Input</a>).  This is the third sample file, called <samp><span class="file">tao</span></samp>:
  2364.  
  2365. <pre class="example">     The Way that can be told of is not the eternal Way;
  2366.      The name that can be named is not the eternal name.
  2367.      The Nameless is the origin of Heaven and Earth;
  2368.      The named is the mother of all things.
  2369.      
  2370.      Therefore let there always be non-being,
  2371.        so we may see their subtlety,
  2372.      And let there always be being,
  2373.        so we may see their result.
  2374.      The two are the same,
  2375.      But after they are produced,
  2376.        they have different names.
  2377.      
  2378.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2379. </pre>
  2380.    <div class="node">
  2381. <p><hr>
  2382. <a name="Detailed-diff3-Normal"></a>
  2383. Next: <a rel="next" accesskey="n" href="#diff3-Hunks">diff3 Hunks</a>,
  2384. Previous: <a rel="previous" accesskey="p" href="#Sample-diff3-Input">Sample diff3 Input</a>,
  2385. Up: <a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>
  2386.  
  2387. </div>
  2388.  
  2389. <h3 class="section">7.2 Detailed Description of <samp><span class="command">diff3</span></samp> Normal Format</h3>
  2390.  
  2391. <p>Each hunk begins with a line marked `<samp><span class="samp">====</span></samp>'.  Three-way hunks have
  2392. plain `<samp><span class="samp">====</span></samp>' lines, and two-way hunks have `<samp><span class="samp">1</span></samp>', `<samp><span class="samp">2</span></samp>', or
  2393. `<samp><span class="samp">3</span></samp>' appended to specify which of the three input files differ in
  2394. that hunk.  The hunks contain copies of two or three sets of input
  2395. lines each preceded by one or two commands identifying where the lines
  2396. came from.
  2397.  
  2398.    <p>Normally, two spaces precede each copy of an input line to distinguish
  2399. it from the commands.  But with the <samp><span class="option">-T</span></samp> or <samp><span class="option">--initial-tab</span></samp>
  2400. option, <samp><span class="command">diff3</span></samp> uses a tab instead of two spaces; this lines up
  2401. tabs correctly.  See <a href="#Tabs">Tabs</a>, for more information.
  2402.  
  2403.    <p>Commands take the following forms:
  2404.  
  2405.      <dl>
  2406. <dt>`<samp><var>file</var><span class="samp">:</span><var>l</var><span class="samp">a</span></samp>'<dd>This hunk appears after line <var>l</var> of file <var>file</var>, and
  2407. contains no lines in that file.  To edit this file to yield the other
  2408. files, one must append hunk lines taken from the other files.  For
  2409. example, `<samp><span class="samp">1:11a</span></samp>' means that the hunk follows line 11 in the first
  2410. file and contains no lines from that file.
  2411.  
  2412.      <br><dt>`<samp><var>file</var><span class="samp">:</span><var>r</var><span class="samp">c</span></samp>'<dd>This hunk contains the lines in the range <var>r</var> of file <var>file</var>. 
  2413. The range <var>r</var> is a comma-separated pair of line numbers, or just one
  2414. number if the range is a singleton.  To edit this file to yield the
  2415. other files, one must change the specified lines to be the lines taken
  2416. from the other files.  For example, `<samp><span class="samp">2:11,13c</span></samp>' means that the hunk
  2417. contains lines 11 through 13 from the second file. 
  2418. </dl>
  2419.  
  2420.    <p>If the last line in a set of input lines is incomplete
  2421. (see <a href="#Incomplete-Lines">Incomplete Lines</a>), it is distinguished on output from a full
  2422. line by a following line that starts with `<samp><span class="samp">\</span></samp>'.
  2423.  
  2424. <div class="node">
  2425. <p><hr>
  2426. <a name="diff3-Hunks"></a>
  2427. Next: <a rel="next" accesskey="n" href="#Example-diff3-Normal">Example diff3 Normal</a>,
  2428. Previous: <a rel="previous" accesskey="p" href="#Detailed-diff3-Normal">Detailed diff3 Normal</a>,
  2429. Up: <a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>
  2430.  
  2431. </div>
  2432.  
  2433. <h3 class="section">7.3 <samp><span class="command">diff3</span></samp> Hunks</h3>
  2434.  
  2435. <p><a name="index-hunks-for-_0040command_007bdiff3_007d-62"></a><a name="index-g_t_0040command_007bdiff3_007d-hunks-63"></a>
  2436. Groups of lines that differ in two or three of the input files are
  2437. called <dfn>diff3 hunks</dfn>, by analogy with <samp><span class="command">diff</span></samp> hunks
  2438. (see <a href="#Hunks">Hunks</a>).  If all three input files differ in a <samp><span class="command">diff3</span></samp>
  2439. hunk, the hunk is called a <dfn>three-way hunk</dfn>; if just two input files
  2440. differ, it is a <dfn>two-way hunk</dfn>.
  2441.  
  2442.    <p>As with <samp><span class="command">diff</span></samp>, several solutions are possible.  When comparing the
  2443. files `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>', and `<samp><span class="samp">C</span></samp>', <samp><span class="command">diff3</span></samp> normally finds
  2444. <samp><span class="command">diff3</span></samp> hunks by merging the two-way hunks output by the two
  2445. commands `<samp><span class="samp">diff A B</span></samp>' and `<samp><span class="samp">diff A C</span></samp>'.  This does not necessarily
  2446. minimize the size of the output, but exceptions should be rare.
  2447.  
  2448.    <p>For example, suppose <samp><span class="file">F</span></samp> contains the three lines `<samp><span class="samp">a</span></samp>',
  2449. `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">f</span></samp>', <samp><span class="file">G</span></samp> contains the lines `<samp><span class="samp">g</span></samp>', `<samp><span class="samp">b</span></samp>',
  2450. `<samp><span class="samp">g</span></samp>', and <samp><span class="file">H</span></samp> contains the lines `<samp><span class="samp">a</span></samp>', `<samp><span class="samp">b</span></samp>',
  2451. `<samp><span class="samp">h</span></samp>'.  `<samp><span class="samp">diff3 F G H</span></samp>' might output the following:
  2452.  
  2453. <pre class="example">     ====2
  2454.      1:1c
  2455.      3:1c
  2456.        a
  2457.      2:1c
  2458.        g
  2459.      ====
  2460.      1:3c
  2461.        f
  2462.      2:3c
  2463.        g
  2464.      3:3c
  2465.        h
  2466. </pre>
  2467.    <p class="noindent">because it found a two-way hunk containing `<samp><span class="samp">a</span></samp>' in the first and
  2468. third files and `<samp><span class="samp">g</span></samp>' in the second file, then the single line
  2469. `<samp><span class="samp">b</span></samp>' common to all three files, then a three-way hunk containing
  2470. the last line of each file.
  2471.  
  2472. <div class="node">
  2473. <p><hr>
  2474. <a name="Example-diff3-Normal"></a>
  2475. Previous: <a rel="previous" accesskey="p" href="#diff3-Hunks">diff3 Hunks</a>,
  2476. Up: <a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>
  2477.  
  2478. </div>
  2479.  
  2480. <h3 class="section">7.4 An Example of <samp><span class="command">diff3</span></samp> Normal Format</h3>
  2481.  
  2482. <p>Here is the output of the command `<samp><span class="samp">diff3 lao tzu tao</span></samp>'
  2483. (see <a href="#Sample-diff3-Input">Sample diff3 Input</a>, for the complete contents of the files). 
  2484. Notice that it shows only the lines that are different among the three
  2485. files.
  2486.  
  2487. <pre class="example">     ====2
  2488.      1:1,2c
  2489.      3:1,2c
  2490.        The Way that can be told of is not the eternal Way;
  2491.        The name that can be named is not the eternal name.
  2492.      2:0a
  2493.      ====1
  2494.      1:4c
  2495.        The Named is the mother of all things.
  2496.      2:2,3c
  2497.      3:4,5c
  2498.        The named is the mother of all things.
  2499.      
  2500.      ====3
  2501.      1:8c
  2502.      2:7c
  2503.          so we may see their outcome.
  2504.      3:9c
  2505.          so we may see their result.
  2506.      ====
  2507.      1:11a
  2508.      2:11,13c
  2509.        They both may be called deep and profound.
  2510.        Deeper and more profound,
  2511.        The door of all subtleties!
  2512.      3:13,14c
  2513.      
  2514.          -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2515. </pre>
  2516.    <div class="node">
  2517. <p><hr>
  2518. <a name="diff3-Merging"></a>
  2519. Next: <a rel="next" accesskey="n" href="#Interactive-Merging">Interactive Merging</a>,
  2520. Previous: <a rel="previous" accesskey="p" href="#Comparing-Three-Files">Comparing Three Files</a>,
  2521. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2522.  
  2523. </div>
  2524.  
  2525. <h2 class="chapter">8 Merging From a Common Ancestor</h2>
  2526.  
  2527. <p><a name="index-merging-from-a-common-ancestor-64"></a>
  2528. When two people have made changes to copies of the same file,
  2529. <samp><span class="command">diff3</span></samp> can produce a merged output that contains both sets of
  2530. changes together with warnings about conflicts.
  2531.  
  2532.    <p>One might imagine programs with names like <samp><span class="command">diff4</span></samp> and <samp><span class="command">diff5</span></samp>
  2533. to compare more than three files simultaneously, but in practice the
  2534. need rarely arises.  You can use <samp><span class="command">diff3</span></samp> to merge three or more
  2535. sets of changes to a file by merging two change sets at a time.
  2536.  
  2537.    <p><samp><span class="command">diff3</span></samp> can incorporate changes from two modified versions into a
  2538. common preceding version.  This lets you merge the sets of changes
  2539. represented by the two newer files.  Specify the common ancestor version
  2540. as the second argument and the two newer versions as the first and third
  2541. arguments, like this:
  2542.  
  2543. <pre class="example">     diff3 <var>mine</var> <var>older</var> <var>yours</var>
  2544. </pre>
  2545.    <p class="noindent">You can remember the order of the arguments by noting that they are in
  2546. alphabetical order.
  2547.  
  2548.    <p><a name="index-conflict-65"></a><a name="index-overlap-66"></a>You can think of this as subtracting <var>older</var> from <var>yours</var> and
  2549. adding the result to <var>mine</var>, or as merging into <var>mine</var> the
  2550. changes that would turn <var>older</var> into <var>yours</var>.  This merging is
  2551. well-defined as long as <var>mine</var> and <var>older</var> match in the
  2552. neighborhood of each such change.  This fails to be true when all three
  2553. input files differ or when only <var>older</var> differs; we call this
  2554. a <dfn>conflict</dfn>.  When all three input files differ, we call the
  2555. conflict an <dfn>overlap</dfn>.
  2556.  
  2557.    <p><samp><span class="command">diff3</span></samp> gives you several ways to handle overlaps and conflicts. 
  2558. You can omit overlaps or conflicts, or select only overlaps,
  2559. or mark conflicts with special `<samp><span class="samp"><<<<<<<</span></samp>' and `<samp><span class="samp">>>>>>>></span></samp>' lines.
  2560.  
  2561.    <p><samp><span class="command">diff3</span></samp> can output the merge results as an <samp><span class="command">ed</span></samp> script that
  2562. that can be applied to the first file to yield the merged output. 
  2563. However, it is usually better to have <samp><span class="command">diff3</span></samp> generate the merged
  2564. output directly; this bypasses some problems with <samp><span class="command">ed</span></samp>.
  2565.  
  2566. <ul class="menu">
  2567. <li><a accesskey="1" href="#Which-Changes">Which Changes</a>:             Selecting changes to incorporate. 
  2568. <li><a accesskey="2" href="#Marking-Conflicts">Marking Conflicts</a>:         Marking conflicts. 
  2569. <li><a accesskey="3" href="#Bypassing-ed">Bypassing ed</a>:              Generating merged output directly. 
  2570. <li><a accesskey="4" href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a>:  How <samp><span class="command">diff3</span></samp> merges incomplete lines. 
  2571. <li><a accesskey="5" href="#Saving-the-Changed-File">Saving the Changed File</a>:   Emulating System V behavior. 
  2572. </ul>
  2573.  
  2574. <div class="node">
  2575. <p><hr>
  2576. <a name="Which-Changes"></a>
  2577. Next: <a rel="next" accesskey="n" href="#Marking-Conflicts">Marking Conflicts</a>,
  2578. Up: <a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>
  2579.  
  2580. </div>
  2581.  
  2582. <h3 class="section">8.1 Selecting Which Changes to Incorporate</h3>
  2583.  
  2584. <p><a name="index-overlapping-change_002c-selection-of-67"></a><a name="index-unmerged-change-68"></a>
  2585. You can select all unmerged changes from <var>older</var> to <var>yours</var> for merging
  2586. into <var>mine</var> with the <samp><span class="option">-e</span></samp> or <samp><span class="option">--ed</span></samp> option.  You can
  2587. select only the nonoverlapping unmerged changes with <samp><span class="option">-3</span></samp> or
  2588. <samp><span class="option">--easy-only</span></samp>, and you can select only the overlapping changes with
  2589. <samp><span class="option">-x</span></samp> or <samp><span class="option">--overlap-only</span></samp>.
  2590.  
  2591.    <p>The <samp><span class="option">-e</span></samp>, <samp><span class="option">-3</span></samp> and <samp><span class="option">-x</span></samp> options select only
  2592. <dfn>unmerged changes</dfn>, i.e. changes where <var>mine</var> and <var>yours</var>
  2593. differ; they ignore changes from <var>older</var> to <var>yours</var> where
  2594. <var>mine</var> and <var>yours</var> are identical, because they assume that such
  2595. changes have already been merged.  If this assumption is not a safe
  2596. one, you can use the <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option
  2597. (see <a href="#Marking-Conflicts">Marking Conflicts</a>).
  2598.  
  2599.    <p>Here is the output of the command <samp><span class="command">diff3</span></samp> with each of these three
  2600. options (see <a href="#Sample-diff3-Input">Sample diff3 Input</a>, for the complete contents of the files). 
  2601. Notice that <samp><span class="option">-e</span></samp> outputs the union of the disjoint sets of changes
  2602. output by <samp><span class="option">-3</span></samp> and <samp><span class="option">-x</span></samp>.
  2603.  
  2604.    <p>Output of `<samp><span class="samp">diff3 -e lao tzu tao</span></samp>':
  2605. <pre class="example">     11a
  2606.      
  2607.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2608.      .
  2609.      8c
  2610.        so we may see their result.
  2611.      .
  2612. </pre>
  2613.    <p>Output of `<samp><span class="samp">diff3 -3 lao tzu tao</span></samp>':
  2614. <pre class="example">     8c
  2615.        so we may see their result.
  2616.      .
  2617. </pre>
  2618.    <p>Output of `<samp><span class="samp">diff3 -x lao tzu tao</span></samp>':
  2619. <pre class="example">     11a
  2620.      
  2621.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2622.      .
  2623. </pre>
  2624.    <div class="node">
  2625. <p><hr>
  2626. <a name="Marking-Conflicts"></a>
  2627. Next: <a rel="next" accesskey="n" href="#Bypassing-ed">Bypassing ed</a>,
  2628. Previous: <a rel="previous" accesskey="p" href="#Which-Changes">Which Changes</a>,
  2629. Up: <a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>
  2630.  
  2631. </div>
  2632.  
  2633. <h3 class="section">8.2 Marking Conflicts</h3>
  2634.  
  2635. <p><a name="index-conflict-marking-69"></a><a name="index-g_t_0040samp_007b_003c_003c_003c_003c_003c_003c_003c_007d-for-marking-conflicts-70"></a>
  2636. <samp><span class="command">diff3</span></samp> can mark conflicts in the merged output by
  2637. bracketing them with special marker lines.  A conflict
  2638. that comes from two files <var>A</var> and <var>B</var> is marked as follows:
  2639.  
  2640. <pre class="example">     <<<<<<< <var>A</var>
  2641.      <span class="roman">lines from </span><var>A</var>
  2642.      =======
  2643.      <span class="roman">lines from </span><var>B</var>
  2644.      >>>>>>> <var>B</var>
  2645. </pre>
  2646.    <p>A conflict that comes from three files <var>A</var>, <var>B</var> and <var>C</var> is
  2647. marked as follows:
  2648.  
  2649. <pre class="example">     <<<<<<< <var>A</var>
  2650.      <span class="roman">lines from </span><var>A</var>
  2651.      ||||||| <var>B</var>
  2652.      <span class="roman">lines from </span><var>B</var>
  2653.      =======
  2654.      <span class="roman">lines from </span><var>C</var>
  2655.      >>>>>>> <var>C</var>
  2656. </pre>
  2657.    <p>The <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option acts like the <samp><span class="option">-e</span></samp>
  2658. option, except that it brackets conflicts, and it outputs all changes
  2659. from <var>older</var> to <var>yours</var>, not just the unmerged changes.  Thus,
  2660. given the sample input files (see <a href="#Sample-diff3-Input">Sample diff3 Input</a>), `<samp><span class="samp">diff3
  2661. -A lao tzu tao</span></samp>' puts brackets around the conflict where only <samp><span class="file">tzu</span></samp>
  2662. differs:
  2663.  
  2664. <pre class="example">     <<<<<<< tzu
  2665.      =======
  2666.      The Way that can be told of is not the eternal Way;
  2667.      The name that can be named is not the eternal name.
  2668.      >>>>>>> tao
  2669. </pre>
  2670.    <p>And it outputs the three-way conflict as follows:
  2671.  
  2672. <pre class="example">     <<<<<<< lao
  2673.      ||||||| tzu
  2674.      They both may be called deep and profound.
  2675.      Deeper and more profound,
  2676.      The door of all subtleties!
  2677.      =======
  2678.      
  2679.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2680.      >>>>>>> tao
  2681. </pre>
  2682.    <p>The <samp><span class="option">-E</span></samp> or <samp><span class="option">--show-overlap</span></samp> option outputs less information
  2683. than the <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option, because it outputs only
  2684. unmerged changes, and it never outputs the contents of the second
  2685. file.  Thus the <samp><span class="option">-E</span></samp> option acts like the <samp><span class="option">-e</span></samp> option,
  2686. except that it brackets the first and third files from three-way
  2687. overlapping changes.  Similarly, <samp><span class="option">-X</span></samp> acts like <samp><span class="option">-x</span></samp>, except
  2688. it brackets all its (necessarily overlapping) changes.  For example,
  2689. for the three-way overlapping change above, the <samp><span class="option">-E</span></samp> and <samp><span class="option">-X</span></samp>
  2690. options output the following:
  2691.  
  2692. <pre class="example">     <<<<<<< lao
  2693.      =======
  2694.      
  2695.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2696.      >>>>>>> tao
  2697. </pre>
  2698.    <p>If you are comparing files that have meaningless or uninformative names,
  2699. you can use the <samp><span class="option">-L </span><var>label</var></samp> or <samp><span class="option">--label=</span><var>label</var></samp>
  2700. option to show alternate names in the `<samp><span class="samp"><<<<<<<</span></samp>', `<samp><span class="samp">|||||||</span></samp>'
  2701. and `<samp><span class="samp">>>>>>>></span></samp>' brackets.  This option can be given up to three
  2702. times, once for each input file.  Thus `<samp><span class="samp">diff3 -A -L X -L Y -L Z A
  2703. B C</span></samp>' acts like `<samp><span class="samp">diff3 -A A B C</span></samp>', except that the output looks like
  2704. it came from files named `<samp><span class="samp">X</span></samp>', `<samp><span class="samp">Y</span></samp>' and `<samp><span class="samp">Z</span></samp>' rather than
  2705. from files named `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>' and `<samp><span class="samp">C</span></samp>'.
  2706.  
  2707. <div class="node">
  2708. <p><hr>
  2709. <a name="Bypassing-ed"></a>
  2710. Next: <a rel="next" accesskey="n" href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a>,
  2711. Previous: <a rel="previous" accesskey="p" href="#Marking-Conflicts">Marking Conflicts</a>,
  2712. Up: <a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>
  2713.  
  2714. </div>
  2715.  
  2716. <h3 class="section">8.3 Generating the Merged Output Directly</h3>
  2717.  
  2718. <p><a name="index-merged-_0040command_007bdiff3_007d-format-71"></a>
  2719. With the <samp><span class="option">-m</span></samp> or <samp><span class="option">--merge</span></samp> option, <samp><span class="command">diff3</span></samp> outputs the
  2720. merged file directly.  This is more efficient than using <samp><span class="command">ed</span></samp> to
  2721. generate it, and works even with non-text files that <samp><span class="command">ed</span></samp> would
  2722. reject.  If you specify <samp><span class="option">-m</span></samp> without an <samp><span class="command">ed</span></samp> script option,
  2723. <samp><span class="option">-A</span></samp> (<samp><span class="option">--show-all</span></samp>) is assumed.
  2724.  
  2725.    <p>For example, the command `<samp><span class="samp">diff3 -m lao tzu tao</span></samp>'
  2726. (see <a href="#Sample-diff3-Input">Sample diff3 Input</a> for a copy of the input files) would output
  2727. the following:
  2728.  
  2729. <pre class="example">     <<<<<<< tzu
  2730.      =======
  2731.      The Way that can be told of is not the eternal Way;
  2732.      The name that can be named is not the eternal name.
  2733.      >>>>>>> tao
  2734.      The Nameless is the origin of Heaven and Earth;
  2735.      The Named is the mother of all things.
  2736.      Therefore let there always be non-being,
  2737.        so we may see their subtlety,
  2738.      And let there always be being,
  2739.        so we may see their result.
  2740.      The two are the same,
  2741.      But after they are produced,
  2742.        they have different names.
  2743.      <<<<<<< lao
  2744.      ||||||| tzu
  2745.      They both may be called deep and profound.
  2746.      Deeper and more profound,
  2747.      The door of all subtleties!
  2748.      =======
  2749.      
  2750.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  2751.      >>>>>>> tao
  2752. </pre>
  2753.    <div class="node">
  2754. <p><hr>
  2755. <a name="Merging-Incomplete-Lines"></a>
  2756. Next: <a rel="next" accesskey="n" href="#Saving-the-Changed-File">Saving the Changed File</a>,
  2757. Previous: <a rel="previous" accesskey="p" href="#Bypassing-ed">Bypassing ed</a>,
  2758. Up: <a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>
  2759.  
  2760. </div>
  2761.  
  2762. <h3 class="section">8.4 How <samp><span class="command">diff3</span></samp> Merges Incomplete Lines</h3>
  2763.  
  2764. <p><a name="index-incomplete-line-merging-72"></a>
  2765. With <samp><span class="option">-m</span></samp>, incomplete lines (see <a href="#Incomplete-Lines">Incomplete Lines</a>) are simply
  2766. copied to the output as they are found; if the merged output ends in an
  2767. conflict and one of the input files ends in an incomplete
  2768. line, succeeding `<samp><span class="samp">|||||||</span></samp>', `<samp><span class="samp">=======</span></samp>' or `<samp><span class="samp">>>>>>>></span></samp>'
  2769. brackets appear somewhere other than the start of a line because
  2770. they are appended to the incomplete line.
  2771.  
  2772.    <p>Without <samp><span class="option">-m</span></samp>, if an <samp><span class="command">ed</span></samp> script option is specified and an
  2773. incomplete line is found, <samp><span class="command">diff3</span></samp> generates a warning and acts as
  2774. if a newline had been present.
  2775.  
  2776. <div class="node">
  2777. <p><hr>
  2778. <a name="Saving-the-Changed-File"></a>
  2779. Previous: <a rel="previous" accesskey="p" href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a>,
  2780. Up: <a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>
  2781.  
  2782. </div>
  2783.  
  2784. <h3 class="section">8.5 Saving the Changed File</h3>
  2785.  
  2786. <p><a name="index-System-V-_0040command_007bdiff3_007d-compatibility-73"></a>
  2787. Traditional Unix <samp><span class="command">diff3</span></samp> generates an <samp><span class="command">ed</span></samp> script without the
  2788. trailing `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>' commands that save the changes. 
  2789. System V <samp><span class="command">diff3</span></samp> generates these extra commands.  <span class="sc">gnu</span>
  2790. <samp><span class="command">diff3</span></samp> normally behaves like traditional Unix
  2791. <samp><span class="command">diff3</span></samp>, but with the <samp><span class="option">-i</span></samp> option it behaves like
  2792. System V <samp><span class="command">diff3</span></samp> and appends the `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>'
  2793. commands.
  2794.  
  2795.    <p>The <samp><span class="option">-i</span></samp> option requires one of the <samp><span class="command">ed</span></samp> script options
  2796. <samp><span class="option">-AeExX3</span></samp>, and is incompatible with the merged output option
  2797. <samp><span class="option">-m</span></samp>.
  2798.  
  2799. <div class="node">
  2800. <p><hr>
  2801. <a name="Interactive-Merging"></a>
  2802. Next: <a rel="next" accesskey="n" href="#Merging-with-patch">Merging with patch</a>,
  2803. Previous: <a rel="previous" accesskey="p" href="#diff3-Merging">diff3 Merging</a>,
  2804. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2805.  
  2806. </div>
  2807.  
  2808. <h2 class="chapter">9 Interactive Merging with <samp><span class="command">sdiff</span></samp></h2>
  2809.  
  2810. <p><a name="index-diff-merging-74"></a><a name="index-interactive-merging-75"></a>
  2811. With <samp><span class="command">sdiff</span></samp>, you can merge two files interactively based on a
  2812. side-by-side <samp><span class="option">-y</span></samp> format comparison (see <a href="#Side-by-Side">Side by Side</a>).  Use
  2813. <samp><span class="option">-o </span><var>file</var></samp> or <samp><span class="option">--output=</span><var>file</var></samp> to specify where to
  2814. put the merged text.  See <a href="#Invoking-sdiff">Invoking sdiff</a>, for more details on the
  2815. options to <samp><span class="command">sdiff</span></samp>.
  2816.  
  2817.    <p>Another way to merge files interactively is to use the Emacs Lisp
  2818. package <samp><span class="command">emerge</span></samp>.  See <a href="emacs.html#emerge">emerge</a>, for more information.
  2819.  
  2820. <ul class="menu">
  2821. <li><a accesskey="1" href="#sdiff-Option-Summary">sdiff Option Summary</a>:  Summary of <samp><span class="command">sdiff</span></samp> options. 
  2822. <li><a accesskey="2" href="#Merge-Commands">Merge Commands</a>:        Merging two files interactively. 
  2823. </ul>
  2824.  
  2825. <div class="node">
  2826. <p><hr>
  2827. <a name="sdiff-Option-Summary"></a>
  2828. Next: <a rel="next" accesskey="n" href="#Merge-Commands">Merge Commands</a>,
  2829. Up: <a rel="up" accesskey="u" href="#Interactive-Merging">Interactive Merging</a>
  2830.  
  2831. </div>
  2832.  
  2833. <h3 class="section">9.1 Specifying <samp><span class="command">diff</span></samp> Options to <samp><span class="command">sdiff</span></samp></h3>
  2834.  
  2835. <p><a name="index-g_t_0040command_007bsdiff_007d-output-format-76"></a>
  2836. The following <samp><span class="command">sdiff</span></samp> options have the same meaning as for
  2837. <samp><span class="command">diff</span></samp>.  See <a href="#diff-Options">diff Options</a>, for the use of these options.
  2838.  
  2839. <pre class="example">     -a -b -d -i -t -v
  2840.      -B -E -I <var>regexp</var>
  2841.      
  2842.      --ignore-blank-lines  --ignore-case
  2843.      --ignore-matching-lines=<var>regexp</var>  --ignore-space-change
  2844.      --ignore-tab-expansion
  2845.      --left-column  --minimal  --speed-large-files
  2846.      --strip-trailing-cr  --suppress-common-lines  --expand-tabs
  2847.      --text  --version  --width=<var>columns</var>
  2848. </pre>
  2849.    <p>For historical reasons, <samp><span class="command">sdiff</span></samp> has alternate names for some
  2850. options.  The <samp><span class="option">-l</span></samp> option is equivalent to the
  2851. <samp><span class="option">--left-column</span></samp> option, and similarly <samp><span class="option">-s</span></samp> is equivalent
  2852. to <samp><span class="option">--suppress-common-lines</span></samp>.  The meaning of the <samp><span class="command">sdiff</span></samp>
  2853. <samp><span class="option">-w</span></samp> and <samp><span class="option">-W</span></samp> options is interchanged from that of
  2854. <samp><span class="command">diff</span></samp>: with <samp><span class="command">sdiff</span></samp>, <samp><span class="option">-w </span><var>columns</var></samp> is
  2855. equivalent to <samp><span class="option">--width=</span><var>columns</var></samp>, and <samp><span class="option">-W</span></samp> is
  2856. equivalent to <samp><span class="option">--ignore-all-space</span></samp>.  <samp><span class="command">sdiff</span></samp> without the
  2857. <samp><span class="option">-o</span></samp> option is equivalent to <samp><span class="command">diff</span></samp> with the <samp><span class="option">-y</span></samp>
  2858. or <samp><span class="option">--side-by-side</span></samp> option (see <a href="#Side-by-Side">Side by Side</a>).
  2859.  
  2860. <div class="node">
  2861. <p><hr>
  2862. <a name="Merge-Commands"></a>
  2863. Previous: <a rel="previous" accesskey="p" href="#sdiff-Option-Summary">sdiff Option Summary</a>,
  2864. Up: <a rel="up" accesskey="u" href="#Interactive-Merging">Interactive Merging</a>
  2865.  
  2866. </div>
  2867.  
  2868. <h3 class="section">9.2 Merge Commands</h3>
  2869.  
  2870. <p><a name="index-merge-commands-77"></a><a name="index-merging-interactively-78"></a>
  2871. Groups of common lines, with a blank gutter, are copied from the first
  2872. file to the output.  After each group of differing lines, <samp><span class="command">sdiff</span></samp>
  2873. prompts with `<samp><span class="samp">%</span></samp>' and pauses, waiting for one of the following
  2874. commands.  Follow each command with <RET>.
  2875.  
  2876.      <dl>
  2877. <dt>`<samp><span class="samp">e</span></samp>'<dd>Discard both versions. 
  2878. Invoke a text editor on an empty temporary file,
  2879. then copy the resulting file to the output.
  2880.  
  2881.      <br><dt>`<samp><span class="samp">eb</span></samp>'<dd>Concatenate the two versions, edit the result in a temporary file,
  2882. then copy the edited result to the output.
  2883.  
  2884.      <br><dt>`<samp><span class="samp">ed</span></samp>'<dd>Like `<samp><span class="samp">eb</span></samp>', except precede each version with a header that
  2885. shows what file and lines the version came from.
  2886.  
  2887.      <br><dt>`<samp><span class="samp">el</span></samp>'<dd>Edit a copy of the left version, then copy the result to the output.
  2888.  
  2889.      <br><dt>`<samp><span class="samp">er</span></samp>'<dd>Edit a copy of the right version, then copy the result to the output.
  2890.  
  2891.      <br><dt>`<samp><span class="samp">l</span></samp>'<dd>Copy the left version to the output.
  2892.  
  2893.      <br><dt>`<samp><span class="samp">q</span></samp>'<dd>Quit.
  2894.  
  2895.      <br><dt>`<samp><span class="samp">r</span></samp>'<dd>Copy the right version to the output.
  2896.  
  2897.      <br><dt>`<samp><span class="samp">s</span></samp>'<dd>Silently copy common lines.
  2898.  
  2899.      <br><dt>`<samp><span class="samp">v</span></samp>'<dd>Verbosely copy common lines.  This is the default. 
  2900. </dl>
  2901.  
  2902.    <p><a name="index-EDITOR-79"></a>The text editor invoked is specified by the <samp><span class="env">EDITOR</span></samp> environment
  2903. variable if it is set.  The default is system-dependent.
  2904.  
  2905. <div class="node">
  2906. <p><hr>
  2907. <a name="Merging-with-patch"></a>
  2908. Next: <a rel="next" accesskey="n" href="#Making-Patches">Making Patches</a>,
  2909. Previous: <a rel="previous" accesskey="p" href="#Interactive-Merging">Interactive Merging</a>,
  2910. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  2911.  
  2912. </div>
  2913.  
  2914. <h2 class="chapter">10 Merging with <samp><span class="command">patch</span></samp></h2>
  2915.  
  2916. <p><samp><span class="command">patch</span></samp> takes comparison output produced by <samp><span class="command">diff</span></samp> and applies
  2917. the differences to a copy of the original file, producing a patched
  2918. version.  With <samp><span class="command">patch</span></samp>, you can distribute just the changes to a
  2919. set of files instead of distributing the entire file set; your
  2920. correspondents can apply <samp><span class="command">patch</span></samp> to update their copy of the files
  2921. with your changes.  <samp><span class="command">patch</span></samp> automatically determines the diff
  2922. format, skips any leading or trailing headers, and uses the headers to
  2923. determine which file to patch.  This lets your correspondents feed a
  2924. mail message containing a difference listing directly to
  2925. <samp><span class="command">patch</span></samp>.
  2926.  
  2927.    <p><samp><span class="command">patch</span></samp> detects and warns about common problems like forward
  2928. patches.  It saves any patches that it could not apply.  It can also maintain a
  2929. <code>patchlevel.h</code> file to ensure that your correspondents apply
  2930. diffs in the proper order.
  2931.  
  2932.    <p><samp><span class="command">patch</span></samp> accepts a series of diffs in its standard input, usually
  2933. separated by headers that specify which file to patch.  It applies
  2934. <samp><span class="command">diff</span></samp> hunks (see <a href="#Hunks">Hunks</a>) one by one.  If a hunk does not
  2935. exactly match the original file, <samp><span class="command">patch</span></samp> uses heuristics to try to
  2936. patch the file as well as it can.  If no approximate match can be found,
  2937. <samp><span class="command">patch</span></samp> rejects the hunk and skips to the next hunk.  <samp><span class="command">patch</span></samp>
  2938. normally replaces each file <var>f</var> with its new version, putting reject
  2939. hunks (if any) into `<samp><var>f</var><span class="samp">.rej</span></samp>'.
  2940.  
  2941.    <p>See <a href="#Invoking-patch">Invoking patch</a>, for detailed information on the options to
  2942. <samp><span class="command">patch</span></samp>.
  2943.  
  2944. <ul class="menu">
  2945. <li><a accesskey="1" href="#patch-Input">patch Input</a>:             Selecting the type of <samp><span class="command">patch</span></samp> input. 
  2946. <li><a accesskey="2" href="#Revision-Control">Revision Control</a>:        Getting files from <span class="sc">rcs</span>, <span class="sc">sccs</span>, etc. 
  2947. <li><a accesskey="3" href="#Imperfect">Imperfect</a>:               Dealing with imperfect patches. 
  2948. <li><a accesskey="4" href="#Creating-and-Removing">Creating and Removing</a>:   Creating and removing files with a patch. 
  2949. <li><a accesskey="5" href="#Patching-Time-Stamps">Patching Time Stamps</a>:    Updating time stamps on patched files. 
  2950. <li><a accesskey="6" href="#Multiple-Patches">Multiple Patches</a>:        Handling multiple patches in a file. 
  2951. <li><a accesskey="7" href="#patch-Directories">patch Directories</a>:       Changing directory and stripping directories. 
  2952. <li><a accesskey="8" href="#Backups">Backups</a>:                 Whether backup files are made. 
  2953. <li><a accesskey="9" href="#Backup-Names">Backup Names</a>:            Backup file names. 
  2954. <li><a href="#Reject-Names">Reject Names</a>:            Reject file names. 
  2955. <li><a href="#patch-Messages">patch Messages</a>:          Messages and questions <samp><span class="command">patch</span></samp> can produce. 
  2956. <li><a href="#patch-and-POSIX">patch and POSIX</a>:         Conformance to the <span class="sc">posix</span> standard. 
  2957. <li><a href="#patch-and-Tradition">patch and Tradition</a>:     <span class="sc">gnu</span> versus traditional <samp><span class="command">patch</span></samp>. 
  2958. </ul>
  2959.  
  2960. <div class="node">
  2961. <p><hr>
  2962. <a name="patch-Input"></a>
  2963. Next: <a rel="next" accesskey="n" href="#Revision-Control">Revision Control</a>,
  2964. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  2965.  
  2966. </div>
  2967.  
  2968. <h3 class="section">10.1 Selecting the <samp><span class="command">patch</span></samp> Input Format</h3>
  2969.  
  2970. <p><a name="index-g_t_0040command_007bpatch_007d-input-format-80"></a>
  2971. <samp><span class="command">patch</span></samp> normally determines which <samp><span class="command">diff</span></samp> format the patch
  2972. file uses by examining its contents.  For patch files that contain
  2973. particularly confusing leading text, you might need to use one of the
  2974. following options to force <samp><span class="command">patch</span></samp> to interpret the patch file as a
  2975. certain format of diff.  The output formats listed here are the only
  2976. ones that <samp><span class="command">patch</span></samp> can understand.
  2977.  
  2978.      <dl>
  2979. <dt><samp><span class="option">-c</span></samp><dt><samp><span class="option">--context</span></samp><dd>context diff.
  2980.  
  2981.      <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd><samp><span class="command">ed</span></samp> script.
  2982.  
  2983.      <br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--normal</span></samp><dd>normal diff.
  2984.  
  2985.      <br><dt><samp><span class="option">-u</span></samp><dt><samp><span class="option">--unified</span></samp><dd>unified diff. 
  2986. </dl>
  2987.  
  2988. <div class="node">
  2989. <p><hr>
  2990. <a name="Revision-Control"></a>
  2991. Next: <a rel="next" accesskey="n" href="#Imperfect">Imperfect</a>,
  2992. Previous: <a rel="previous" accesskey="p" href="#patch-Input">patch Input</a>,
  2993. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  2994.  
  2995. </div>
  2996.  
  2997. <h3 class="section">10.2 Revision Control</h3>
  2998.  
  2999. <p><a name="index-revision-control-81"></a><a name="index-version-control-82"></a><a name="index-g_t_0040sc_007brcs_007d-83"></a><a name="index-ClearCase-84"></a><a name="index-g_t_0040sc_007bsccs_007d-85"></a>
  3000. If a nonexistent input file is under a revision control system
  3001. supported by <samp><span class="command">patch</span></samp>, <samp><span class="command">patch</span></samp> normally asks the user
  3002. whether to get (or check out) the file from the revision control
  3003. system.  Patch currently supports <span class="sc">rcs</span>, ClearCase and <span class="sc">sccs</span>. 
  3004. Under <span class="sc">rcs</span> and <span class="sc">sccs</span>, <samp><span class="command">patch</span></samp> also asks when the input
  3005. file is read-only and matches the default version in the revision
  3006. control system.
  3007.  
  3008.    <p><a name="index-PATCH_005fGET-86"></a>The <samp><span class="option">-g </span><var>num</var></samp> or <samp><span class="option">--get=</span><var>num</var></samp> affects access
  3009. to files under supported revision control systems.  If <var>num</var> is
  3010. positive, <samp><span class="command">patch</span></samp> gets the file without asking the user; if
  3011. zero, <samp><span class="command">patch</span></samp> neither asks the user nor gets the file; and if
  3012. negative, <samp><span class="command">patch</span></samp> asks the user before getting the file.  The
  3013. default value of <var>num</var> is given by the value of the
  3014. <samp><span class="env">PATCH_GET</span></samp> environment variable if it is set; if not, the default
  3015. value is zero if <samp><span class="command">patch</span></samp> is conforming to <span class="sc">posix</span>, negative
  3016. otherwise.  See <a href="#patch-and-POSIX">patch and POSIX</a>.
  3017.  
  3018.    <p><a name="index-VERSION_005fCONTROL-87"></a>The choice of revision control system is unaffected by the
  3019. <samp><span class="env">VERSION_CONTROL</span></samp> environment variable (see <a href="#Backup-Names">Backup Names</a>).
  3020.  
  3021. <div class="node">
  3022. <p><hr>
  3023. <a name="Imperfect"></a>
  3024. Next: <a rel="next" accesskey="n" href="#Creating-and-Removing">Creating and Removing</a>,
  3025. Previous: <a rel="previous" accesskey="p" href="#Revision-Control">Revision Control</a>,
  3026. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3027.  
  3028. </div>
  3029.  
  3030. <h3 class="section">10.3 Applying Imperfect Patches</h3>
  3031.  
  3032. <p><a name="index-imperfect-patch-application-88"></a>
  3033. <samp><span class="command">patch</span></samp> tries to skip any leading text in the patch file,
  3034. apply the diff, and then skip any trailing text.  Thus you can feed a
  3035. mail message directly to <samp><span class="command">patch</span></samp>, and it should work.  If the
  3036. entire diff is indented by a constant amount of white space,
  3037. <samp><span class="command">patch</span></samp> automatically ignores the indentation.  If a context
  3038. diff contains trailing carriage return on each line, <samp><span class="command">patch</span></samp>
  3039. automatically ignores the carriage return.  If a context diff has been
  3040. encapsulated by prepending `<samp><span class="samp">- </span></samp>'<!-- /@w --> to lines beginning with `<samp><span class="samp">-</span></samp>'
  3041. as per <a href="ftp://ftp.isi.edu/in-notes/rfc934.txt">Internet RFC 934</a>,
  3042. <samp><span class="command">patch</span></samp> automatically unencapsulates the input.
  3043.  
  3044.    <p>However, certain other types of imperfect input require user
  3045. intervention or testing.
  3046.  
  3047. <ul class="menu">
  3048. <li><a accesskey="1" href="#Changed-White-Space">Changed White Space</a>:  When tabs and spaces don't match exactly. 
  3049. <li><a accesskey="2" href="#Reversed-Patches">Reversed Patches</a>:     Applying reversed patches correctly. 
  3050. <li><a accesskey="3" href="#Inexact">Inexact</a>:              Helping <samp><span class="command">patch</span></samp> find close matches. 
  3051. <li><a accesskey="4" href="#Dry-Runs">Dry Runs</a>:             Predicting what <samp><span class="command">patch</span></samp> will do. 
  3052. </ul>
  3053.  
  3054. <div class="node">
  3055. <p><hr>
  3056. <a name="Changed-White-Space"></a>
  3057. Next: <a rel="next" accesskey="n" href="#Reversed-Patches">Reversed Patches</a>,
  3058. Up: <a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>
  3059.  
  3060. </div>
  3061.  
  3062. <h4 class="subsection">10.3.1 Applying Patches with Changed White Space</h4>
  3063.  
  3064. <p><a name="index-white-space-in-patches-89"></a>
  3065. Sometimes mailers, editors, or other programs change spaces into tabs,
  3066. or vice versa.  If this happens to a patch file or an input file, the
  3067. files might look the same, but <samp><span class="command">patch</span></samp> will not be able to match
  3068. them properly.  If this problem occurs, use the <samp><span class="option">-l</span></samp> or
  3069. <samp><span class="option">--ignore-white-space</span></samp> option, which makes <samp><span class="command">patch</span></samp> compare
  3070. blank characters (i.e. spaces and tabs) loosely so that any nonempty
  3071. sequence of blanks in the patch file matches any nonempty sequence of
  3072. blanks in the input files.  Non-blank
  3073. characters must still match exactly.  Each line of the context must
  3074. still match a line in the input file.
  3075.  
  3076. <div class="node">
  3077. <p><hr>
  3078. <a name="Reversed-Patches"></a>
  3079. Next: <a rel="next" accesskey="n" href="#Inexact">Inexact</a>,
  3080. Previous: <a rel="previous" accesskey="p" href="#Changed-White-Space">Changed White Space</a>,
  3081. Up: <a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>
  3082.  
  3083. </div>
  3084.  
  3085. <h4 class="subsection">10.3.2 Applying Reversed Patches</h4>
  3086.  
  3087. <p><a name="index-reversed-patches-90"></a>
  3088. Sometimes people run <samp><span class="command">diff</span></samp> with the new file first instead of
  3089. second.  This creates a diff that is “reversed”.  To apply such
  3090. patches, give <samp><span class="command">patch</span></samp> the <samp><span class="option">-R</span></samp> or <samp><span class="option">--reverse</span></samp> option. 
  3091. <samp><span class="command">patch</span></samp> then attempts to swap each hunk around before applying it. 
  3092. Rejects come out in the swapped format.
  3093.  
  3094.    <p>Often <samp><span class="command">patch</span></samp> can guess that the patch is reversed.  If the first
  3095. hunk of a patch fails, <samp><span class="command">patch</span></samp> reverses the hunk to see if it can
  3096. apply it that way.  If it can, <samp><span class="command">patch</span></samp> asks you if you want to have
  3097. the <samp><span class="option">-R</span></samp> option set; if it can't, <samp><span class="command">patch</span></samp> continues to apply
  3098. the patch normally.  This method cannot detect a reversed patch if it is
  3099. a normal diff and the first command is an append (which should have been
  3100. a delete) since appends always succeed, because a null context matches
  3101. anywhere.  But most patches add or change lines rather than delete them,
  3102. so most reversed normal diffs begin with a delete, which fails, and
  3103. <samp><span class="command">patch</span></samp> notices.
  3104.  
  3105.    <p>If you apply a patch that you have already applied, <samp><span class="command">patch</span></samp> thinks
  3106. it is a reversed patch and offers to un-apply the patch.  This could be
  3107. construed as a feature.  If you did this inadvertently and you don't
  3108. want to un-apply the patch, just answer `<samp><span class="samp">n</span></samp>' to this offer and to
  3109. the subsequent “apply anyway” question—or type <kbd>C-c</kbd> to kill the
  3110. <samp><span class="command">patch</span></samp> process.
  3111.  
  3112. <div class="node">
  3113. <p><hr>
  3114. <a name="Inexact"></a>
  3115. Next: <a rel="next" accesskey="n" href="#Dry-Runs">Dry Runs</a>,
  3116. Previous: <a rel="previous" accesskey="p" href="#Reversed-Patches">Reversed Patches</a>,
  3117. Up: <a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>
  3118.  
  3119. </div>
  3120.  
  3121. <h4 class="subsection">10.3.3 Helping <samp><span class="command">patch</span></samp> Find Inexact Matches</h4>
  3122.  
  3123. <p><a name="index-inexact-patches-91"></a><a name="index-fuzz-factor-when-patching-92"></a>
  3124. For context diffs, and to a lesser extent normal diffs, <samp><span class="command">patch</span></samp> can
  3125. detect when the line numbers mentioned in the patch are incorrect, and
  3126. it attempts to find the correct place to apply each hunk of the patch. 
  3127. As a first guess, it takes the line number mentioned in the hunk, plus
  3128. or minus any offset used in applying the previous hunk.  If that is not
  3129. the correct place, <samp><span class="command">patch</span></samp> scans both forward and backward for a
  3130. set of lines matching the context given in the hunk.
  3131.  
  3132.    <p>First <samp><span class="command">patch</span></samp> looks for a place where all lines of the context
  3133. match.  If it cannot find such a place, and it is reading a context or
  3134. unified diff, and the maximum fuzz factor is set to 1 or more, then
  3135. <samp><span class="command">patch</span></samp> makes another scan, ignoring the first and last line of
  3136. context.  If that fails, and the maximum fuzz factor is set to 2 or
  3137. more, it makes another scan, ignoring the first two and last two lines
  3138. of context are ignored.  It continues similarly if the maximum fuzz
  3139. factor is larger.
  3140.  
  3141.    <p>The <samp><span class="option">-F </span><var>lines</var></samp> or <samp><span class="option">--fuzz=</span><var>lines</var></samp> option sets the
  3142. maximum fuzz factor to <var>lines</var>.  This option only applies to context
  3143. and unified diffs; it ignores up to <var>lines</var> lines while looking for
  3144. the place to install a hunk.  Note that a larger fuzz factor increases
  3145. the odds of making a faulty patch.  The default fuzz factor is 2; there
  3146. is no point to setting it to more than the number of lines of context
  3147. in the diff, ordinarily 3.
  3148.  
  3149.    <p>If <samp><span class="command">patch</span></samp> cannot find a place to install a hunk of the patch, it
  3150. writes the hunk out to a reject file (see <a href="#Reject-Names">Reject Names</a>, for information
  3151. on how reject files are named).  It writes out rejected hunks in context
  3152. format no matter what form the input patch is in.  If the input is a
  3153. normal or <samp><span class="command">ed</span></samp> diff, many of the contexts are simply null.  The
  3154. line numbers on the hunks in the reject file may be different from those
  3155. in the patch file: they show the approximate location where <samp><span class="command">patch</span></samp>
  3156. thinks the failed hunks belong in the new file rather than in the old
  3157. one.
  3158.  
  3159.    <p>If the <samp><span class="option">--verbose</span></samp> option is given, then
  3160. as it completes each hunk <samp><span class="command">patch</span></samp> tells you whether the hunk
  3161. succeeded or failed, and if it failed, on which line (in the new file)
  3162. <samp><span class="command">patch</span></samp> thinks the hunk should go.  If this is different from the
  3163. line number specified in the diff, it tells you the offset.  A single
  3164. large offset <em>may</em> indicate that <samp><span class="command">patch</span></samp> installed a hunk in
  3165. the wrong place.  <samp><span class="command">patch</span></samp> also tells you if it used a fuzz factor
  3166. to make the match, in which case you should also be slightly suspicious.
  3167.  
  3168.    <p><samp><span class="command">patch</span></samp> cannot tell if the line numbers are off in an <samp><span class="command">ed</span></samp>
  3169. script, and can only detect wrong line numbers in a normal diff when it
  3170. finds a change or delete command.  It may have the same problem with a
  3171. context diff using a fuzz factor equal to or greater than the number of
  3172. lines of context shown in the diff (typically 3).  In these cases, you
  3173. should probably look at a context diff between your original and patched
  3174. input files to see if the changes make sense.  Compiling without errors
  3175. is a pretty good indication that the patch worked, but not a guarantee.
  3176.  
  3177.    <p>A patch against an empty file applies to a nonexistent file, and vice
  3178. versa.  See <a href="#Creating-and-Removing">Creating and Removing</a>.
  3179.  
  3180.    <p><samp><span class="command">patch</span></samp> usually produces the correct results, even when it must
  3181. make many guesses.  However, the results are guaranteed only when
  3182. the patch is applied to an exact copy of the file that the patch was
  3183. generated from.
  3184.  
  3185. <div class="node">
  3186. <p><hr>
  3187. <a name="Dry-Runs"></a>
  3188. Previous: <a rel="previous" accesskey="p" href="#Inexact">Inexact</a>,
  3189. Up: <a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>
  3190.  
  3191. </div>
  3192.  
  3193. <h4 class="subsection">10.3.4 Predicting what <samp><span class="command">patch</span></samp> will do</h4>
  3194.  
  3195. <p><a name="index-testing-_0040command_007bpatch_007d-93"></a><a name="index-dry-runs-for-_0040command_007bpatch_007d-94"></a>
  3196. It may not be obvious in advance what <samp><span class="command">patch</span></samp> will do with a
  3197. complicated or poorly formatted patch.  If you are concerned that the
  3198. input might cause <samp><span class="command">patch</span></samp> to modify the wrong files, you can
  3199. use the <samp><span class="option">--dry-run</span></samp> option, which causes <samp><span class="command">patch</span></samp> to
  3200. print the results of applying patches without actually changing any
  3201. files.  You can then inspect the diagnostics generated by the dry run
  3202. to see whether <samp><span class="command">patch</span></samp> will modify the files that you expect. 
  3203. If the patch does not do what you want, you can modify the patch (or
  3204. the other options to <samp><span class="command">patch</span></samp>) and try another dry run.  Once
  3205. you are satisfied with the proposed patch you can apply it by invoking
  3206. <samp><span class="command">patch</span></samp> as before, but this time without the
  3207. <samp><span class="option">--dry-run</span></samp> option.
  3208.  
  3209. <div class="node">
  3210. <p><hr>
  3211. <a name="Creating-and-Removing"></a>
  3212. Next: <a rel="next" accesskey="n" href="#Patching-Time-Stamps">Patching Time Stamps</a>,
  3213. Previous: <a rel="previous" accesskey="p" href="#Imperfect">Imperfect</a>,
  3214. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3215.  
  3216. </div>
  3217.  
  3218. <h3 class="section">10.4 Creating and Removing Files</h3>
  3219.  
  3220. <p><a name="index-creating-files-95"></a><a name="index-empty-files_002c-removing-96"></a><a name="index-removing-empty-files-97"></a>
  3221. Sometimes when comparing two directories, a file may exist in one
  3222. directory but not the other.  If you give <samp><span class="command">diff</span></samp> the
  3223. <samp><span class="option">-N</span></samp> or <samp><span class="option">--new-file</span></samp> option, or if you supply an old or
  3224. new file that is named <samp><span class="file">/dev/null</span></samp> or is empty and is dated the
  3225. Epoch (1970-01-01 00:00:00 UTC), <samp><span class="command">diff</span></samp> outputs a patch that
  3226. adds or deletes the contents of this file.  When given such a patch,
  3227. <samp><span class="command">patch</span></samp> normally creates a new file or removes the old file. 
  3228. However, when conforming to <span class="sc">posix</span> (see <a href="#patch-and-POSIX">patch and POSIX</a>),
  3229. <samp><span class="command">patch</span></samp> does not remove the old file, but leaves it empty. 
  3230. The <samp><span class="option">-E</span></samp> or <samp><span class="option">--remove-empty-files</span></samp> option causes
  3231. <samp><span class="command">patch</span></samp> to remove output files that are empty after applying a
  3232. patch, even if the patch does not appear to be one that removed the
  3233. file.
  3234.  
  3235.    <p>If the patch appears to create a file that already exists,
  3236. <samp><span class="command">patch</span></samp> asks for confirmation before applying the patch.
  3237.  
  3238. <div class="node">
  3239. <p><hr>
  3240. <a name="Patching-Time-Stamps"></a>
  3241. Next: <a rel="next" accesskey="n" href="#Multiple-Patches">Multiple Patches</a>,
  3242. Previous: <a rel="previous" accesskey="p" href="#Creating-and-Removing">Creating and Removing</a>,
  3243. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3244.  
  3245. </div>
  3246.  
  3247. <h3 class="section">10.5 Updating Time Stamps on Patched Files</h3>
  3248.  
  3249. <p><a name="index-time-stamps-on-patched-files-98"></a>
  3250. When <samp><span class="command">patch</span></samp> updates a file, it normally sets the file's
  3251. last-modified time stamp to the current time of day.  If you are using
  3252. <samp><span class="command">patch</span></samp> to track a software distribution, this can cause
  3253. <samp><span class="command">make</span></samp> to incorrectly conclude that a patched file is out of
  3254. date.  For example, if <samp><span class="file">syntax.c</span></samp> depends on <samp><span class="file">syntax.y</span></samp>, and
  3255. <samp><span class="command">patch</span></samp> updates <samp><span class="file">syntax.c</span></samp> and then <samp><span class="file">syntax.y</span></samp>, then
  3256. <samp><span class="file">syntax.c</span></samp> will normally appear to be out of date with respect to
  3257. <samp><span class="file">syntax.y</span></samp> even though its contents are actually up to date.
  3258.  
  3259.    <p>The <samp><span class="option">-Z</span></samp> or <samp><span class="option">--set-utc</span></samp> option causes <samp><span class="command">patch</span></samp> to
  3260. set a patched file's modification and access times to the time stamps
  3261. given in context diff headers.  If the context diff headers do not
  3262. specify a time zone, they are assumed to use Coordinated Universal
  3263. Time (<span class="sc">utc</span>, often known as <span class="sc">gmt</span>).
  3264.  
  3265.    <p>The <samp><span class="option">-T</span></samp> or <samp><span class="option">--set-time</span></samp> option acts like <samp><span class="option">-Z</span></samp> or
  3266. <samp><span class="option">--set-utc</span></samp>, except that it assumes that the context diff
  3267. headers' time stamps use local time instead of <span class="sc">utc</span>.  This option
  3268. is not recommended, because patches using local time cannot easily be
  3269. used by people in other time zones, and because local time stamps are
  3270. ambiguous when local clocks move backwards during daylight-saving time
  3271. adjustments.  If the context diff headers specify a time zone, this
  3272. option is equivalent to <samp><span class="option">-Z</span></samp> or <samp><span class="option">--set-utc</span></samp>.
  3273.  
  3274.    <p><samp><span class="command">patch</span></samp> normally refrains from setting a file's time stamps if
  3275. the file's original last-modified time stamp does not match the time
  3276. given in the diff header, of if the file's contents do not exactly
  3277. match the patch.  However, if the <samp><span class="option">-f</span></samp> or <samp><span class="option">--force</span></samp>
  3278. option is given, the file's time stamps are set regardless.
  3279.  
  3280.    <p>Due to the limitations of the current <samp><span class="command">diff</span></samp> format,
  3281. <samp><span class="command">patch</span></samp> cannot update the times of files whose contents have
  3282. not changed.  Also, if you set file time stamps to values other than
  3283. the current time of day, you should also remove (e.g., with `<samp><span class="samp">make
  3284. clean</span></samp>') all files that depend on the patched files, so that later
  3285. invocations of <samp><span class="command">make</span></samp> do not get confused by the patched
  3286. files' times.
  3287.  
  3288. <div class="node">
  3289. <p><hr>
  3290. <a name="Multiple-Patches"></a>
  3291. Next: <a rel="next" accesskey="n" href="#patch-Directories">patch Directories</a>,
  3292. Previous: <a rel="previous" accesskey="p" href="#Patching-Time-Stamps">Patching Time Stamps</a>,
  3293. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3294.  
  3295. </div>
  3296.  
  3297. <h3 class="section">10.6 Multiple Patches in a File</h3>
  3298.  
  3299. <p><a name="index-multiple-patches-99"></a><a name="index-intuiting-file-names-from-patches-100"></a>
  3300. If the patch file contains more than one patch, and if you do not
  3301. specify an input file on the command line, <samp><span class="command">patch</span></samp> tries to
  3302. apply each patch as if they came from separate patch files.  This
  3303. means that it determines the name of the file to patch for each patch,
  3304. and that it examines the leading text before each patch for file names
  3305. and prerequisite revision level (see <a href="#Making-Patches">Making Patches</a>, for more on
  3306. that topic).
  3307.  
  3308.    <p><samp><span class="command">patch</span></samp> uses the following rules to intuit a file name from
  3309. the leading text before a patch.  First, <samp><span class="command">patch</span></samp> takes an
  3310. ordered list of candidate file names as follows:
  3311.  
  3312.      <ul>
  3313. <li>If the header is that of a context diff, <samp><span class="command">patch</span></samp> takes the old
  3314. and new file names in the header.  A name is ignored if it does not
  3315. have enough slashes to satisfy the <samp><span class="option">-p</span><var>num</var></samp> or
  3316. <samp><span class="option">--strip=</span><var>num</var></samp> option.  The name <samp><span class="file">/dev/null</span></samp> is also
  3317. ignored.
  3318.  
  3319.      <li>If there is an `<samp><span class="samp">Index:</span></samp>' line in the leading garbage and if either
  3320. the old and new names are both absent or if <samp><span class="command">patch</span></samp> is
  3321. conforming to <span class="sc">posix</span>, <samp><span class="command">patch</span></samp> takes the name in the
  3322. `<samp><span class="samp">Index:</span></samp>' line.
  3323.  
  3324.      <li>For the purpose of the following rules, the candidate file names are
  3325. considered to be in the order (old, new, index), regardless of the
  3326. order that they appear in the header. 
  3327. </ul>
  3328.  
  3329. <p class="noindent">Then <samp><span class="command">patch</span></samp> selects a file name from the candidate list as
  3330. follows:
  3331.  
  3332.      <ul>
  3333. <li>If some of the named files exist, <samp><span class="command">patch</span></samp> selects the first
  3334. name if conforming to <span class="sc">posix</span>, and the best name otherwise.
  3335.  
  3336.      <li>If <samp><span class="command">patch</span></samp> is not ignoring <span class="sc">rcs</span>, ClearCase, and <span class="sc">sccs</span>
  3337. (see <a href="#Revision-Control">Revision Control</a>), and no named files exist but an <span class="sc">rcs</span>,
  3338. ClearCase, or <span class="sc">sccs</span> master is found, <samp><span class="command">patch</span></samp> selects the
  3339. first named file with an <span class="sc">rcs</span>, ClearCase, or <span class="sc">sccs</span> master.
  3340.  
  3341.      <li>If no named files exist, no <span class="sc">rcs</span>, ClearCase, or <span class="sc">sccs</span> master
  3342. was found, some names are given, <samp><span class="command">patch</span></samp> is not conforming to
  3343. <span class="sc">posix</span>, and the patch appears to create a file, <samp><span class="command">patch</span></samp>
  3344. selects the best name requiring the creation of the fewest
  3345. directories.
  3346.  
  3347.      <li>If no file name results from the above heuristics, you are asked for
  3348. the name of the file to patch, and <samp><span class="command">patch</span></samp> selects that name. 
  3349. </ul>
  3350.  
  3351.    <p>To determine the <dfn>best</dfn> of a nonempty list of file names,
  3352. <samp><span class="command">patch</span></samp> first takes all the names with the fewest path name
  3353. components; of those, it then takes all the names with the shortest
  3354. basename; of those, it then takes all the shortest names; finally, it
  3355. takes the first remaining name.
  3356.  
  3357.    <p>See <a href="#patch-and-POSIX">patch and POSIX</a>, to see whether <samp><span class="command">patch</span></samp> is conforming
  3358. to <span class="sc">posix</span>.
  3359.  
  3360. <div class="node">
  3361. <p><hr>
  3362. <a name="patch-Directories"></a>
  3363. Next: <a rel="next" accesskey="n" href="#Backups">Backups</a>,
  3364. Previous: <a rel="previous" accesskey="p" href="#Multiple-Patches">Multiple Patches</a>,
  3365. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3366.  
  3367. </div>
  3368.  
  3369. <h3 class="section">10.7 Applying Patches in Other Directories</h3>
  3370.  
  3371. <p><a name="index-directories-and-patch-101"></a><a name="index-patching-directories-102"></a>
  3372. The <samp><span class="option">-d </span><var>directory</var></samp> or <samp><span class="option">--directory=</span><var>directory</var></samp>
  3373. option to <samp><span class="command">patch</span></samp> makes directory <var>directory</var> the current
  3374. directory for interpreting both file names in the patch file, and file
  3375. names given as arguments to other options (such as <samp><span class="option">-B</span></samp> and
  3376. <samp><span class="option">-o</span></samp>).  For example, while in a mail reading program, you can patch
  3377. a file in the <samp><span class="file">/usr/src/emacs</span></samp> directory directly from a message
  3378. containing the patch like this:
  3379.  
  3380. <pre class="example">     | patch -d /usr/src/emacs
  3381. </pre>
  3382.    <p>Sometimes the file names given in a patch contain leading directories,
  3383. but you keep your files in a directory different from the one given in
  3384. the patch.  In those cases, you can use the
  3385. <samp><span class="option">-p</span><var>number</var></samp> or <samp><span class="option">--strip=</span><var>number</var></samp>
  3386. option to set the file name strip count to <var>number</var>.  The strip
  3387. count tells <samp><span class="command">patch</span></samp> how many slashes, along with the directory
  3388. names between them, to strip from the front of file names.  A sequence
  3389. of one or more adjacent slashes is counted as a single slash.  By
  3390. default, <samp><span class="command">patch</span></samp> strips off all leading directories, leaving
  3391. just the base file names.
  3392.  
  3393.    <p>For example, suppose the file name in the patch file is
  3394. <samp><span class="file">/gnu/src/emacs/etc/NEWS</span></samp>.  Using <samp><span class="option">-p0</span></samp> gives the
  3395. entire file name unmodified, <samp><span class="option">-p1</span></samp> gives
  3396. <samp><span class="file">gnu/src/emacs/etc/NEWS</span></samp> (no leading slash), <samp><span class="option">-p4</span></samp> gives
  3397. <samp><span class="file">etc/NEWS</span></samp>, and not specifying <samp><span class="option">-p</span></samp> at all gives <samp><span class="file">NEWS</span></samp>.
  3398.  
  3399.    <p><samp><span class="command">patch</span></samp> looks for each file (after any slashes have been stripped)
  3400. in the current directory, or if you used the <samp><span class="option">-d </span><var>directory</var></samp>
  3401. option, in that directory.
  3402.  
  3403. <div class="node">
  3404. <p><hr>
  3405. <a name="Backups"></a>
  3406. Next: <a rel="next" accesskey="n" href="#Backup-Names">Backup Names</a>,
  3407. Previous: <a rel="previous" accesskey="p" href="#patch-Directories">patch Directories</a>,
  3408. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3409.  
  3410. </div>
  3411.  
  3412. <h3 class="section">10.8 Backup Files</h3>
  3413.  
  3414. <p><a name="index-backup-file-strategy-103"></a>
  3415. Normally, <samp><span class="command">patch</span></samp> creates a backup file if the patch does not
  3416. exactly match the original input file, because in that case the
  3417. original data might not be recovered if you undo the patch with
  3418. `<samp><span class="samp">patch -R</span></samp>' (see <a href="#Reversed-Patches">Reversed Patches</a>).  However, when conforming
  3419. to <span class="sc">posix</span>, <samp><span class="command">patch</span></samp> does not create backup files by
  3420. default.  See <a href="#patch-and-POSIX">patch and POSIX</a>.
  3421.  
  3422.    <p>The <samp><span class="option">-b</span></samp> or <samp><span class="option">--backup</span></samp> option causes <samp><span class="command">patch</span></samp> to
  3423. make a backup file regardless of whether the patch matches the
  3424. original input.  The <samp><span class="option">--backup-if-mismatch</span></samp> option causes
  3425. <samp><span class="command">patch</span></samp> to create backup files for mismatches files; this is
  3426. the default when not conforming to <span class="sc">posix</span>.  The
  3427. <samp><span class="option">--no-backup-if-mismatch</span></samp> option causes <samp><span class="command">patch</span></samp> to not
  3428. create backup files, even for mismatched patches; this is the default
  3429. when conforming to <span class="sc">posix</span>.
  3430.  
  3431.    <p>When backing up a file that does not exist, an empty, unreadable
  3432. backup file is created as a placeholder to represent the nonexistent
  3433. file.
  3434.  
  3435. <div class="node">
  3436. <p><hr>
  3437. <a name="Backup-Names"></a>
  3438. Next: <a rel="next" accesskey="n" href="#Reject-Names">Reject Names</a>,
  3439. Previous: <a rel="previous" accesskey="p" href="#Backups">Backups</a>,
  3440. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3441.  
  3442. </div>
  3443.  
  3444. <h3 class="section">10.9 Backup File Names</h3>
  3445.  
  3446. <p><a name="index-backup-file-names-104"></a>
  3447. Normally, <samp><span class="command">patch</span></samp> renames an original input file into a backup
  3448. file by appending to its name the extension `<samp><span class="samp">.orig</span></samp>', or `<samp><span class="samp">~</span></samp>'
  3449. if using `<samp><span class="samp">.orig</span></samp>' would make the backup file name too
  3450. long.<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a>  The <samp><span class="option">-z </span><var>backup-suffix</var></samp> or
  3451. <samp><span class="option">--suffix=</span><var>backup-suffix</var></samp> option causes <samp><span class="command">patch</span></samp> to
  3452. use <var>backup-suffix</var> as the backup extension instead.
  3453.  
  3454.    <p><a name="index-SIMPLE_005fBACKUP_005fSUFFIX-105"></a>Alternately, you can specify the extension for backup files with the
  3455. <samp><span class="env">SIMPLE_BACKUP_SUFFIX</span></samp> environment variable, which the options
  3456. override.
  3457.  
  3458.    <p><samp><span class="command">patch</span></samp> can also create numbered backup files the way <span class="sc">gnu</span> Emacs
  3459. does.  With this method, instead of having a single backup of each file,
  3460. <samp><span class="command">patch</span></samp> makes a new backup file name each time it patches a file. 
  3461. For example, the backups of a file named <samp><span class="file">sink</span></samp> would be called,
  3462. successively, <samp><span class="file">sink.~1~</span></samp>, <samp><span class="file">sink.~2~</span></samp>, <samp><span class="file">sink.~3~</span></samp>, etc.
  3463.  
  3464.    <p><a name="index-PATCH_005fVERSION_005fCONTROL-106"></a><a name="index-VERSION_005fCONTROL-107"></a>The <samp><span class="option">-V </span><var>backup-style</var></samp> or
  3465. <samp><span class="option">--version-control=</span><var>backup-style</var></samp> option takes as an
  3466. argument a method for creating backup file names.  You can alternately
  3467. control the type of backups that <samp><span class="command">patch</span></samp> makes with the
  3468. <samp><span class="env">PATCH_VERSION_CONTROL</span></samp> environment variable, which the
  3469. <samp><span class="option">-V</span></samp> option overrides.  If <samp><span class="env">PATCH_VERSION_CONTROL</span></samp> is not
  3470. set, the <samp><span class="env">VERSION_CONTROL</span></samp> environment variable is used instead. 
  3471. Please note that these options and variables control backup file
  3472. names; they do not affect the choice of revision control system
  3473. (see <a href="#Revision-Control">Revision Control</a>).
  3474.  
  3475.    <p>The values of these environment variables and the argument to the
  3476. <samp><span class="option">-V</span></samp> option are like the <span class="sc">gnu</span> Emacs <code>version-control</code>
  3477. variable (see <a href="emacs.html#Backup-Names">Backup Names</a>,
  3478. for more information on backup versions in Emacs).  They also
  3479. recognize synonyms that are more descriptive.  The valid values are
  3480. listed below; unique abbreviations are acceptable.
  3481.  
  3482.      <dl>
  3483. <dt><samp><span class="option">t</span></samp><dt><samp><span class="option">numbered</span></samp><dd>Always make numbered backups.
  3484.  
  3485.      <br><dt><samp><span class="option">nil</span></samp><dt><samp><span class="option">existing</span></samp><dd>Make numbered backups of files that already have them, simple backups of
  3486. the others.  This is the default.
  3487.  
  3488.      <br><dt><samp><span class="option">never</span></samp><dt><samp><span class="option">simple</span></samp><dd>Always make simple backups. 
  3489. </dl>
  3490.  
  3491.    <p>You can also tell <samp><span class="command">patch</span></samp> to prepend a prefix, such as a
  3492. directory name, to produce backup file names.  The <samp><span class="option">-B
  3493. </span><var>prefix</var></samp> or <samp><span class="option">--prefix=</span><var>prefix</var></samp> option makes backup
  3494. files by prepending <var>prefix</var> to them.  The <samp><span class="option">-Y
  3495. </span><var>prefix</var></samp> or <samp><span class="option">--basename-prefix=</span><var>prefix</var></samp> prepends
  3496. <var>prefix</var> to the last file name component of backup file names
  3497. instead; for example, <samp><span class="option">-Y ~</span></samp> causes the backup name for
  3498. <samp><span class="file">dir/file.c</span></samp> to be <samp><span class="file">dir/~file.c</span></samp>.  If you use either of
  3499. these prefix options, the suffix-based options are ignored.
  3500.  
  3501.    <p>If you specify the output file with the <samp><span class="option">-o</span></samp> option, that file is
  3502. the one that is backed up, not the input file.
  3503.  
  3504.    <p>Options that affect the names of backup files do not affect whether
  3505. backups are made.  For example, if you specify the
  3506. <samp><span class="option">--no-backup-if-mismatch</span></samp> option, none of the options described
  3507. in this section have any affect, because no backups are made.
  3508.  
  3509. <div class="node">
  3510. <p><hr>
  3511. <a name="Reject-Names"></a>
  3512. Next: <a rel="next" accesskey="n" href="#patch-Messages">patch Messages</a>,
  3513. Previous: <a rel="previous" accesskey="p" href="#Backup-Names">Backup Names</a>,
  3514. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3515.  
  3516. </div>
  3517.  
  3518. <h3 class="section">10.10 Reject File Names</h3>
  3519.  
  3520. <p><a name="index-reject-file-names-108"></a>
  3521. The names for reject files (files containing patches that
  3522. <samp><span class="command">patch</span></samp> could not find a place to apply) are normally the name
  3523. of the output file with `<samp><span class="samp">.rej</span></samp>' appended (or `<samp><span class="samp">#</span></samp>' if if using
  3524. `<samp><span class="samp">.rej</span></samp>' would make the backup file name too long).
  3525.  
  3526.    <p>Alternatively, you can tell <samp><span class="command">patch</span></samp> to place all of the rejected
  3527. patches in a single file.  The <samp><span class="option">-r </span><var>reject-file</var></samp> or
  3528. <samp><span class="option">--reject-file=</span><var>reject-file</var></samp> option uses <var>reject-file</var> as
  3529. the reject file name.
  3530.  
  3531. <div class="node">
  3532. <p><hr>
  3533. <a name="patch-Messages"></a>
  3534. Next: <a rel="next" accesskey="n" href="#patch-and-POSIX">patch and POSIX</a>,
  3535. Previous: <a rel="previous" accesskey="p" href="#Reject-Names">Reject Names</a>,
  3536. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3537.  
  3538. </div>
  3539.  
  3540. <h3 class="section">10.11 Messages and Questions from <samp><span class="command">patch</span></samp></h3>
  3541.  
  3542. <p><a name="index-g_t_0040command_007bpatch_007d-messages-and-questions-109"></a><a name="index-diagnostics-from-_0040command_007bpatch_007d-110"></a><a name="index-messages-from-_0040command_007bpatch_007d-111"></a>
  3543. <samp><span class="command">patch</span></samp> can produce a variety of messages, especially if it
  3544. has trouble decoding its input.  In a few situations where it's not
  3545. sure how to proceed, <samp><span class="command">patch</span></samp> normally prompts you for more
  3546. information from the keyboard.  There are options to produce more or
  3547. fewer messages, to have it not ask for keyboard input, and to
  3548. affect the way that file names are quoted in messages.
  3549.  
  3550. <ul class="menu">
  3551. <li><a accesskey="1" href="#More-or-Fewer-Messages">More or Fewer Messages</a>:     Controlling the verbosity of <samp><span class="command">patch</span></samp>. 
  3552. <li><a accesskey="2" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>:   Inhibiting keyboard input. 
  3553. <li><a accesskey="3" href="#patch-Quoting-Style">patch Quoting Style</a>:        Quoting file names in diagnostics. 
  3554. </ul>
  3555.  
  3556.    <p><samp><span class="command">patch</span></samp> exits with status 0 if all hunks are applied successfully,
  3557. 1 if some hunks cannot be applied, and 2 if there is more serious trouble. 
  3558. When applying a set of patches in a loop, you should check the
  3559. exit status, so you don't apply a later patch to a partially patched
  3560. file.
  3561.  
  3562. <div class="node">
  3563. <p><hr>
  3564. <a name="More-or-Fewer-Messages"></a>
  3565. Next: <a rel="next" accesskey="n" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>,
  3566. Up: <a rel="up" accesskey="u" href="#patch-Messages">patch Messages</a>
  3567.  
  3568. </div>
  3569.  
  3570. <h4 class="subsection">10.11.1 Controlling the Verbosity of <samp><span class="command">patch</span></samp></h4>
  3571.  
  3572. <p><a name="index-verbose-messages-from-_0040command_007bpatch_007d-112"></a><a name="index-inhibit-messages-from-_0040command_007bpatch_007d-113"></a>
  3573. You can cause <samp><span class="command">patch</span></samp> to produce more messages by using the
  3574. <samp><span class="option">--verbose</span></samp> option.  For example, when you give this option,
  3575. the message `<samp><span class="samp">Hmm...</span></samp>' indicates that <samp><span class="command">patch</span></samp> is reading text in
  3576. the patch file, attempting to determine whether there is a patch in that
  3577. text, and if so, what kind of patch it is.
  3578.  
  3579.    <p>You can inhibit all terminal output from <samp><span class="command">patch</span></samp>, unless an error
  3580. occurs, by using the <samp><span class="option">-s</span></samp>, <samp><span class="option">--quiet</span></samp>, or <samp><span class="option">--silent</span></samp>
  3581. option.
  3582.  
  3583. <div class="node">
  3584. <p><hr>
  3585. <a name="patch-and-Keyboard-Input"></a>
  3586. Next: <a rel="next" accesskey="n" href="#patch-Quoting-Style">patch Quoting Style</a>,
  3587. Previous: <a rel="previous" accesskey="p" href="#More-or-Fewer-Messages">More or Fewer Messages</a>,
  3588. Up: <a rel="up" accesskey="u" href="#patch-Messages">patch Messages</a>
  3589.  
  3590. </div>
  3591.  
  3592. <h4 class="subsection">10.11.2 Inhibiting Keyboard Input</h4>
  3593.  
  3594. <p><a name="index-keyboard-input-to-_0040command_007bpatch_007d-114"></a>
  3595. There are two ways you can prevent <samp><span class="command">patch</span></samp> from asking you any
  3596. questions.  The <samp><span class="option">-f</span></samp> or <samp><span class="option">--force</span></samp> option assumes that you know
  3597. what you are doing.  It causes <samp><span class="command">patch</span></samp> to do the following:
  3598.  
  3599.      <ul>
  3600. <li>Skip patches that do not contain file names in their headers.
  3601.  
  3602.      <li>Patch files even though they have the wrong version for the
  3603. `<samp><span class="samp">Prereq:</span></samp>' line in the patch;
  3604.  
  3605.      <li>Assume that patches are not reversed even if they look like they are. 
  3606. </ul>
  3607.  
  3608. <p class="noindent">The <samp><span class="option">-t</span></samp> or <samp><span class="option">--batch</span></samp> option is similar to <samp><span class="option">-f</span></samp>, in that
  3609. it suppresses questions, but it makes somewhat different assumptions:
  3610.  
  3611.      <ul>
  3612. <li>Skip patches that do not contain file names in their headers
  3613. (the same as <samp><span class="option">-f</span></samp>).
  3614.  
  3615.      <li>Skip patches for which the file has the wrong version for the
  3616. `<samp><span class="samp">Prereq:</span></samp>' line in the patch;
  3617.  
  3618.      <li>Assume that patches are reversed if they look like they are. 
  3619. </ul>
  3620.  
  3621. <div class="node">
  3622. <p><hr>
  3623. <a name="patch-Quoting-Style"></a>
  3624. Previous: <a rel="previous" accesskey="p" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>,
  3625. Up: <a rel="up" accesskey="u" href="#patch-Messages">patch Messages</a>
  3626.  
  3627. </div>
  3628.  
  3629. <h4 class="subsection">10.11.3 <samp><span class="command">patch</span></samp> Quoting Style</h4>
  3630.  
  3631. <p><a name="index-quoting-style-115"></a>
  3632. When <samp><span class="command">patch</span></samp> outputs a file name in a diagnostic message, it
  3633. can format the name in any of several ways.  This can be useful to
  3634. output file names unambiguously, even if they contain punctuation or
  3635. special characters like newlines.  The
  3636. <samp><span class="option">--quoting-style=</span><var>word</var></samp> option controls how names are
  3637. output.  The <var>word</var> should be one of the following:
  3638.  
  3639.      <dl>
  3640. <dt>`<samp><span class="samp">literal</span></samp>'<dd>Output names as-is. 
  3641. <br><dt>`<samp><span class="samp">shell</span></samp>'<dd>Quote names for the shell if they contain shell metacharacters or would
  3642. cause ambiguous output. 
  3643. <br><dt>`<samp><span class="samp">shell-always</span></samp>'<dd>Quote names for the shell, even if they would normally not require quoting. 
  3644. <br><dt>`<samp><span class="samp">c</span></samp>'<dd>Quote names as for a C language string. 
  3645. <br><dt>`<samp><span class="samp">escape</span></samp>'<dd>Quote as with `<samp><span class="samp">c</span></samp>' except omit the surrounding double-quote
  3646. characters. 
  3647. <!-- The following are not yet implemented in patch 2.5.4. -->
  3648. <!-- @item clocale -->
  3649. <!-- Quote as with @samp{c} except use quotation marks appropriate for the -->
  3650. <!-- locale. -->
  3651. <!-- @item locale -->
  3652. <!-- @c Use @t instead of @samp to avoid duplicate quoting in some output styles. -->
  3653. <!-- Like @samp{clocale}, but quote @t{`like this'} instead of @t{"like -->
  3654. <!-- this"} in the default C locale.  This looks nicer on many displays. -->
  3655. </dl>
  3656.  
  3657.    <p><a name="index-QUOTING_005fSTYLE-116"></a>You can specify the default value of the <samp><span class="option">--quoting-style</span></samp>
  3658. option with the environment variable <samp><span class="env">QUOTING_STYLE</span></samp>.  If that
  3659. environment variable is not set, the default value is `<samp><span class="samp">shell</span></samp>',
  3660. but this default may change in a future version of <samp><span class="command">patch</span></samp>.
  3661.  
  3662. <div class="node">
  3663. <p><hr>
  3664. <a name="patch-and-POSIX"></a>
  3665. Next: <a rel="next" accesskey="n" href="#patch-and-Tradition">patch and Tradition</a>,
  3666. Previous: <a rel="previous" accesskey="p" href="#patch-Messages">patch Messages</a>,
  3667. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3668.  
  3669. </div>
  3670.  
  3671. <h3 class="section">10.12 <samp><span class="command">patch</span></samp> and the <span class="sc">posix</span> Standard</h3>
  3672.  
  3673. <p><a name="index-g_t_0040sc_007bposix_007d-117"></a>
  3674. <a name="index-POSIXLY_005fCORRECT-118"></a>If you specify the <samp><span class="option">--posix</span></samp> option, or set the
  3675. <samp><span class="env">POSIXLY_CORRECT</span></samp> environment variable, <samp><span class="command">patch</span></samp> conforms
  3676. more strictly to the <span class="sc">posix</span> standard, as follows:
  3677.  
  3678.      <ul>
  3679. <li>Take the first existing file from the list (old, new, index)
  3680. when intuiting file names from diff headers.  See <a href="#Multiple-Patches">Multiple Patches</a>.
  3681.  
  3682.      <li>Do not remove files that are removed by a diff. 
  3683. See <a href="#Creating-and-Removing">Creating and Removing</a>.
  3684.  
  3685.      <li>Do not ask whether to get files from <span class="sc">rcs</span>, ClearCase, or
  3686. <span class="sc">sccs</span>.  See <a href="#Revision-Control">Revision Control</a>.
  3687.  
  3688.      <li>Require that all options precede the files in the command line.
  3689.  
  3690.      <li>Do not backup files, even when there is a mismatch.  See <a href="#Backups">Backups</a>.
  3691.  
  3692.    </ul>
  3693.  
  3694. <div class="node">
  3695. <p><hr>
  3696. <a name="patch-and-Tradition"></a>
  3697. Previous: <a rel="previous" accesskey="p" href="#patch-and-POSIX">patch and POSIX</a>,
  3698. Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
  3699.  
  3700. </div>
  3701.  
  3702. <h3 class="section">10.13 <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> and Traditional <samp><span class="command">patch</span></samp></h3>
  3703.  
  3704. <p><a name="index-traditional-_0040command_007bpatch_007d-119"></a>
  3705. The current version of <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> normally follows the
  3706. <span class="sc">posix</span> standard.  See <a href="#patch-and-POSIX">patch and POSIX</a>, for the few exceptions
  3707. to this general rule.
  3708.  
  3709.    <p>Unfortunately, <span class="sc">posix</span> redefined the behavior of <samp><span class="command">patch</span></samp> in
  3710. several important ways.  You should be aware of the following
  3711. differences if you must interoperate with traditional <samp><span class="command">patch</span></samp>,
  3712. or with <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> version 2.1 and earlier.
  3713.  
  3714.      <ul>
  3715. <li>In traditional <samp><span class="command">patch</span></samp>, the <samp><span class="option">-p</span></samp> option's operand was
  3716. optional, and a bare <samp><span class="option">-p</span></samp> was equivalent to <samp><span class="option">-p0</span></samp>.  The
  3717. <samp><span class="option">-p</span></samp> option now requires an operand, and <samp><span class="option">-p 0</span></samp> is now
  3718. equivalent to <samp><span class="option">-p0</span></samp>.  For maximum compatibility, use options
  3719. like <samp><span class="option">-p0</span></samp> and <samp><span class="option">-p1</span></samp>.
  3720.  
  3721.      <p>Also, traditional <samp><span class="command">patch</span></samp> simply counted slashes when
  3722. stripping path prefixes; <samp><span class="command">patch</span></samp> now counts pathname
  3723. components.  That is, a sequence of one or more adjacent slashes now
  3724. counts as a single slash.  For maximum portability, avoid sending
  3725. patches containing <samp><span class="file">//</span></samp> in file names.
  3726.  
  3727.      <li>In traditional <samp><span class="command">patch</span></samp>, backups were enabled by default.  This
  3728. behavior is now enabled with the <samp><span class="option">-b</span></samp> or <samp><span class="option">--backup</span></samp>
  3729. option.
  3730.  
  3731.      <p>Conversely, in <span class="sc">posix</span> <samp><span class="command">patch</span></samp>, backups are never made,
  3732. even when there is a mismatch.  In <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>, this
  3733. behavior is enabled with the <samp><span class="option">--no-backup-if-mismatch</span></samp> option,
  3734. or by conforming to <span class="sc">posix</span>.
  3735.  
  3736.      <p>The <samp><span class="option">-b </span><var>suffix</var></samp> option of traditional <samp><span class="command">patch</span></samp> is
  3737. equivalent to the `<samp><span class="samp">-b -z </span><var>suffix</var></samp>' options of <span class="sc">gnu</span>
  3738. <samp><span class="command">patch</span></samp>.
  3739.  
  3740.      <li>Traditional <samp><span class="command">patch</span></samp> used a complicated (and incompletely
  3741. documented) method to intuit the name of the file to be patched from
  3742. the patch header.  This method did not conform to <span class="sc">posix</span>, and had
  3743. a few gotchas.  Now <samp><span class="command">patch</span></samp> uses a different, equally
  3744. complicated (but better documented) method that is optionally
  3745. <span class="sc">posix</span>-conforming; we hope it has fewer gotchas.  The two methods
  3746. are compatible if the file names in the context diff header and the
  3747. `<samp><span class="samp">Index:</span></samp>' line are all identical after prefix-stripping.  Your
  3748. patch is normally compatible if each header's file names all contain
  3749. the same number of slashes.
  3750.  
  3751.      <li>When traditional <samp><span class="command">patch</span></samp> asked the user a question, it sent
  3752. the question to standard error and looked for an answer from the first
  3753. file in the following list that was a terminal: standard error,
  3754. standard output, <samp><span class="file">/dev/tty</span></samp>, and standard input.  Now
  3755. <samp><span class="command">patch</span></samp> sends questions to standard output and gets answers
  3756. from <samp><span class="file">/dev/tty</span></samp>.  Defaults for some answers have been changed so
  3757. that <samp><span class="command">patch</span></samp> never goes into an infinite loop when using
  3758. default answers.
  3759.  
  3760.      <li>Traditional <samp><span class="command">patch</span></samp> exited with a status value that counted
  3761. the number of bad hunks, or with status 1 if there was real trouble. 
  3762. Now <samp><span class="command">patch</span></samp> exits with status 1 if some hunks failed, or with
  3763. 2 if there was real trouble.
  3764.  
  3765.      <li>Limit yourself to the following options when sending instructions
  3766. meant to be executed by anyone running <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>,
  3767. traditional <samp><span class="command">patch</span></samp>, or a <samp><span class="command">patch</span></samp> that conforms to
  3768. <span class="sc">posix</span>.  Spaces are significant in the following list, and
  3769. operands are required.
  3770.  
  3771.      <pre class="example">          <samp><span class="option">-c</span></samp>
  3772.           <samp><span class="option">-d </span><var>dir</var></samp>
  3773.           <samp><span class="option">-D </span><var>define</var></samp>
  3774.           <samp><span class="option">-e</span></samp>
  3775.           <samp><span class="option">-l</span></samp>
  3776.           <samp><span class="option">-n</span></samp>
  3777.           <samp><span class="option">-N</span></samp>
  3778.           <samp><span class="option">-o </span><var>outfile</var></samp>
  3779.           <samp><span class="option">-p</span><var>num</var></samp>
  3780.           <samp><span class="option">-R</span></samp>
  3781.           <samp><span class="option">-r </span><var>rejectfile</var></samp>
  3782.      </pre>
  3783.      </ul>
  3784.  
  3785. <div class="node">
  3786. <p><hr>
  3787. <a name="Making-Patches"></a>
  3788. Next: <a rel="next" accesskey="n" href="#Invoking-cmp">Invoking cmp</a>,
  3789. Previous: <a rel="previous" accesskey="p" href="#Merging-with-patch">Merging with patch</a>,
  3790. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  3791.  
  3792. </div>
  3793.  
  3794. <h2 class="chapter">11 Tips for Making and Using Patches</h2>
  3795.  
  3796. <p>Use some common sense when making and using patches.  For example,
  3797. when sending bug fixes to a program's maintainer, send several small
  3798. patches, one per independent subject, instead of one large,
  3799. harder-to-digest patch that covers all the subjects.
  3800.  
  3801.    <p>Here are some other things you should keep in mind if you are going to
  3802. distribute patches for updating a software package.
  3803.  
  3804. <ul class="menu">
  3805. <li><a accesskey="1" href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>:     Advice for making patches. 
  3806. <li><a accesskey="2" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>:     Advice for using patches. 
  3807. <li><a accesskey="3" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>:     Avoiding common mistakes when using <samp><span class="command">patch</span></samp>. 
  3808. <li><a accesskey="4" href="#Generating-Smaller-Patches">Generating Smaller Patches</a>:   How to generate smaller patches. 
  3809. </ul>
  3810.  
  3811. <div class="node">
  3812. <p><hr>
  3813. <a name="Tips-for-Patch-Producers"></a>
  3814. Next: <a rel="next" accesskey="n" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>,
  3815. Up: <a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>
  3816.  
  3817. </div>
  3818.  
  3819. <h3 class="section">11.1 Tips for Patch Producers</h3>
  3820.  
  3821. <p><a name="index-patch-producer-tips-120"></a>
  3822. To create a patch that changes an older version of a package into a
  3823. newer version, first make a copy of the older and newer versions in
  3824. adjacent subdirectories.  It is common to do that by unpacking
  3825. <samp><span class="command">tar</span></samp> archives of the two versions.
  3826.  
  3827.    <p>To generate the patch, use the command `<samp><span class="samp">diff -Naur </span><var>old</var>
  3828. <var>new</var></samp>' where <var>old</var> and <var>new</var> identify the old and new
  3829. directories.  The names <var>old</var> and <var>new</var> should not contain any
  3830. slashes.  The <samp><span class="option">-N</span></samp> option lets the patch create and remove
  3831. files; <samp><span class="option">-a</span></samp> lets the patch update non-text files; <samp><span class="option">-u</span></samp>
  3832. generates useful time stamps and enough context; and <samp><span class="option">-r</span></samp> lets
  3833. the patch update subdirectories.  Here is an example command, using
  3834. Bourne shell syntax:
  3835.  
  3836. <pre class="example">     diff -Naur gcc-3.0.3 gcc-3.0.4
  3837. </pre>
  3838.    <p>Tell your recipients how to apply the patches.  This should include
  3839. which working directory to use, and which <samp><span class="command">patch</span></samp> options to
  3840. use; the option `<samp><span class="samp">-p1</span></samp>' is recommended.  Test your procedure by
  3841. pretending to be a recipient and applying your patches to a copy of
  3842. the original files.
  3843.  
  3844.    <p>See <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>, for how to avoid common mistakes when
  3845. generating a patch.
  3846.  
  3847. <div class="node">
  3848. <p><hr>
  3849. <a name="Tips-for-Patch-Consumers"></a>
  3850. Next: <a rel="next" accesskey="n" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>,
  3851. Previous: <a rel="previous" accesskey="p" href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>,
  3852. Up: <a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>
  3853.  
  3854. </div>
  3855.  
  3856. <h3 class="section">11.2 Tips for Patch Consumers</h3>
  3857.  
  3858. <p><a name="index-patch-consumer-tips-121"></a>
  3859. A patch producer should tell recipients how to apply the patches, so
  3860. the first rule of thumb for a patch consumer is to follow the
  3861. instructions supplied with the patch.
  3862.  
  3863.    <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can analyze files with arbitrarily long lines
  3864. and files that end in incomplete lines.  However, older versions of
  3865. <samp><span class="command">patch</span></samp> cannot patch such files.  If you are having trouble
  3866. applying such patches, try upgrading to a recent version of <span class="sc">gnu</span>
  3867. <samp><span class="command">patch</span></samp>.
  3868.  
  3869. <div class="node">
  3870. <p><hr>
  3871. <a name="Avoiding-Common-Mistakes"></a>
  3872. Next: <a rel="next" accesskey="n" href="#Generating-Smaller-Patches">Generating Smaller Patches</a>,
  3873. Previous: <a rel="previous" accesskey="p" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>,
  3874. Up: <a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>
  3875.  
  3876. </div>
  3877.  
  3878. <h3 class="section">11.3 Avoiding Common Mistakes</h3>
  3879.  
  3880. <p><a name="index-common-mistakes-with-patches-122"></a><a name="index-patch_002c-common-mistakes-123"></a>
  3881. When producing a patch for multiple files, apply <samp><span class="command">diff</span></samp> to
  3882. directories whose names do not have slashes.  This reduces confusion
  3883. when the patch consumer specifies the <samp><span class="option">-p</span><var>number</var></samp> option,
  3884. since this option can have surprising results when the old and new
  3885. file names have different numbers of slashes.  For example, do not
  3886. send a patch with a header that looks like this:
  3887.  
  3888. <pre class="example">     diff -Naur v2.0.29/prog/README prog/README
  3889.      --- v2.0.29/prog/README    2002-03-10 23:30:39.942229878 -0800
  3890.      +++ prog/README    2002-03-17 20:49:32.442260588 -0800
  3891. </pre>
  3892.    <p class="noindent">because the two file names have different numbers of slashes, and
  3893. different versions of <samp><span class="command">patch</span></samp> interpret the file names
  3894. differently.  To avoid confusion, send output that looks like this
  3895. instead:
  3896.  
  3897. <pre class="example">     diff -Naur v2.0.29/prog/README v2.0.30/prog/README
  3898.      --- v2.0.29/prog/README    2002-03-10 23:30:39.942229878 -0800
  3899.      +++ v2.0.30/prog/README    2002-03-17 20:49:32.442260588 -0800
  3900. </pre>
  3901.    <p>Make sure you have specified the file names correctly, either in a
  3902. context diff header or with an `<samp><span class="samp">Index:</span></samp>' line.  Take care to not send out
  3903. reversed patches, since these make people wonder whether they have
  3904. already applied the patch.
  3905.  
  3906.    <p>Avoid sending patches that compare backup file names like
  3907. <samp><span class="file">README.orig</span></samp> or <samp><span class="file">README~</span></samp>, since this might confuse
  3908. <samp><span class="command">patch</span></samp> into patching a backup file instead of the real file. 
  3909. Instead, send patches that compare the same base file names in
  3910. different directories, e.g. <samp><span class="file">old/README</span></samp> and <samp><span class="file">new/README</span></samp>.
  3911.  
  3912.    <p>To save people from partially applying a patch before other patches that
  3913. should have gone before it, you can make the first patch in the patch
  3914. file update a file with a name like <samp><span class="file">patchlevel.h</span></samp> or
  3915. <samp><span class="file">version.c</span></samp>, which contains a patch level or version number.  If
  3916. the input file contains the wrong version number, <samp><span class="command">patch</span></samp> will
  3917. complain immediately.
  3918.  
  3919.    <p>An even clearer way to prevent this problem is to put a `<samp><span class="samp">Prereq:</span></samp>'
  3920. line before the patch.  If the leading text in the patch file contains a
  3921. line that starts with `<samp><span class="samp">Prereq:</span></samp>', <samp><span class="command">patch</span></samp> takes the next word
  3922. from that line (normally a version number) and checks whether the next
  3923. input file contains that word, preceded and followed by either
  3924. white space or a newline.  If not, <samp><span class="command">patch</span></samp> prompts you for
  3925. confirmation before proceeding.  This makes it difficult to accidentally
  3926. apply patches in the wrong order.
  3927.  
  3928. <div class="node">
  3929. <p><hr>
  3930. <a name="Generating-Smaller-Patches"></a>
  3931. Previous: <a rel="previous" accesskey="p" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>,
  3932. Up: <a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>
  3933.  
  3934. </div>
  3935.  
  3936. <h3 class="section">11.4 Generating Smaller Patches</h3>
  3937.  
  3938. <p><a name="index-patches_002c-shrinking-124"></a>
  3939. The simplest way to generate a patch is to use `<samp><span class="samp">diff -Naur</span></samp>'
  3940. (see <a href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>), but you might be able to reduce
  3941. the size of the patch by renaming or removing some files before making
  3942. the patch.  If the older version of the package contains any files
  3943. that the newer version does not, or if any files have been renamed
  3944. between the two versions, make a list of <samp><span class="command">rm</span></samp> and <samp><span class="command">mv</span></samp>
  3945. commands for the user to execute in the old version directory before
  3946. applying the patch.  Then run those commands yourself in the scratch
  3947. directory.
  3948.  
  3949.    <p>If there are any files that you don't need to include in the patch
  3950. because they can easily be rebuilt from other files (for example,
  3951. <samp><span class="file">TAGS</span></samp> and output from <samp><span class="command">yacc</span></samp> and <samp><span class="command">makeinfo</span></samp>),
  3952. exclude them from the patch by giving <samp><span class="command">diff</span></samp> the <samp><span class="option">-x
  3953. </span><var>pattern</var></samp> option (see <a href="#Comparing-Directories">Comparing Directories</a>).  If you want
  3954. your patch to modify a derived file because your recipients lack tools
  3955. to build it, make sure that the patch for the derived file follows any
  3956. patches for files that it depends on, so that the recipients' time
  3957. stamps will not confuse <samp><span class="command">make</span></samp>.
  3958.  
  3959.    <p>Now you can create the patch using `<samp><span class="samp">diff -Naur</span></samp>'.  Make sure to
  3960. specify the scratch directory first and the newer directory second.
  3961.  
  3962.    <p>Add to the top of the patch a note telling the user any <samp><span class="command">rm</span></samp> and
  3963. <samp><span class="command">mv</span></samp> commands to run before applying the patch.  Then you can
  3964. remove the scratch directory.
  3965.  
  3966.    <p>You can also shrink the patch size by using fewer lines of context,
  3967. but bear in mind that <samp><span class="command">patch</span></samp> typically needs at least two
  3968. lines for proper operation when patches do not exactly match the input
  3969. files.
  3970.  
  3971. <div class="node">
  3972. <p><hr>
  3973. <a name="Invoking-cmp"></a>
  3974. Next: <a rel="next" accesskey="n" href="#Invoking-diff">Invoking diff</a>,
  3975. Previous: <a rel="previous" accesskey="p" href="#Making-Patches">Making Patches</a>,
  3976. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  3977.  
  3978. </div>
  3979.  
  3980. <h2 class="chapter">12 Invoking <samp><span class="command">cmp</span></samp></h2>
  3981.  
  3982. <p><a name="index-invoking-_0040command_007bcmp_007d-125"></a><a name="index-g_t_0040command_007bcmp_007d-invocation-126"></a>
  3983. The <samp><span class="command">cmp</span></samp> command compares two files, and if they differ,
  3984. tells the first byte and line number where they differ.  Bytes and
  3985. lines are numbered starting with 1.  The arguments of <samp><span class="command">cmp</span></samp>
  3986. are as follows:
  3987.  
  3988. <pre class="example">     cmp <var>options</var>... <var>from-file</var> <span class="roman">[</span><var>to-file</var> <span class="roman">[</span><var>from-skip</var> <span class="roman">[</span><var>to-skip</var><span class="roman">]</span><span class="roman">]</span><span class="roman">]</span>
  3989. </pre>
  3990.    <p>The file name <samp><span class="file">-</span></samp> is always the standard input.  <samp><span class="command">cmp</span></samp>
  3991. also uses the standard input if one file name is omitted.  The
  3992. <var>from-skip</var> and <var>to-skip</var> operands specify how many bytes to
  3993. ignore at the start of each file; they are equivalent to the
  3994. <samp><span class="option">--ignore-initial=</span><var>from-skip</var><span class="option">:</span><var>to-skip</var></samp> option.
  3995.  
  3996.    <p>An exit status of 0 means no differences were found, 1 means some
  3997. differences were found, and 2 means trouble.
  3998.  
  3999. <ul class="menu">
  4000. <li><a accesskey="1" href="#cmp-Options">cmp Options</a>:  Summary of options to <samp><span class="command">cmp</span></samp>. 
  4001. </ul>
  4002.  
  4003. <div class="node">
  4004. <p><hr>
  4005. <a name="cmp-Options"></a>
  4006. Up: <a rel="up" accesskey="u" href="#Invoking-cmp">Invoking cmp</a>
  4007.  
  4008. </div>
  4009.  
  4010. <h3 class="section">12.1 Options to <samp><span class="command">cmp</span></samp></h3>
  4011.  
  4012. <p><a name="index-g_t_0040command_007bcmp_007d-options-127"></a><a name="index-options-for-_0040command_007bcmp_007d-128"></a>
  4013. Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp> accepts. 
  4014. Most options have two equivalent names, one of which is a single letter
  4015. preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name preceded by
  4016. `<samp><span class="samp">--</span></samp>'.  Multiple single letter options (unless they take an
  4017. argument) can be combined into a single command line word: <samp><span class="option">-bl</span></samp> is
  4018. equivalent to <samp><span class="option">-b -l</span></samp>.
  4019.  
  4020.      <dl>
  4021. <dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--print-bytes</span></samp><dd>Print the differing bytes.  Display control bytes as a
  4022. `<samp><span class="samp">^</span></samp>' followed by a letter of the alphabet and precede bytes
  4023. that have the high bit set with `<samp><span class="samp">M-</span></samp>' (which stands for “meta”).
  4024.  
  4025.      <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
  4026.  
  4027.      <br><dt><samp><span class="option">-i </span><var>skip</var></samp><dt><samp><span class="option">--ignore-initial=</span><var>skip</var></samp><dd>Ignore any differences in the first <var>skip</var> bytes of the input
  4028. files.  Treat files with fewer than <var>skip</var> bytes as if they are
  4029. empty.  If <var>skip</var> is of the form
  4030. <samp><var>from-skip</var><span class="option">:</span><var>to-skip</var></samp>, skip the first <var>from-skip</var>
  4031. bytes of the first input file and the first <var>to-skip</var> bytes of the
  4032. second.
  4033.  
  4034.      <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--verbose</span></samp><dd>Print the (decimal) byte numbers and (octal) values of all differing bytes.
  4035.  
  4036.      <br><dt><samp><span class="option">-n </span><var>count</var></samp><dt><samp><span class="option">--bytes=</span><var>count</var></samp><dd>Compare at most <var>count</var> input bytes.
  4037.  
  4038.      <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd>Do not print anything; only return an exit status indicating whether
  4039. the files differ.
  4040.  
  4041.      <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit. 
  4042. </dl>
  4043.  
  4044.    <p>In the above table, operands that are byte counts are normally
  4045. decimal, but may be preceded by `<samp><span class="samp">0</span></samp>' for octal and `<samp><span class="samp">0x</span></samp>' for
  4046. hexadecimal.
  4047.  
  4048.    <p>A byte count can be followed by a suffix to specify a multiple of that
  4049. count; in this case an omitted integer is understood to be 1.  A bare
  4050. size letter, or one followed by `<samp><span class="samp">iB</span></samp>', specifies a multiple using
  4051. powers of 1024.  A size letter followed by `<samp><span class="samp">B</span></samp>' specifies powers
  4052. of 1000 instead.  For example, <samp><span class="option">-n 4M</span></samp> and <samp><span class="option">-n 4MiB</span></samp> are
  4053. equivalent to <samp><span class="option">-n 4194304</span></samp>, whereas <samp><span class="option">-n 4MB</span></samp> is
  4054. equivalent to <samp><span class="option">-n 4000000</span></samp>.  This notation is upward compatible
  4055. with the <a href="http://www.bipm.fr/enus/3_SI/si-prefixes.html">SI prefixes</a> for decimal multiples and with the
  4056. <a href="http://physics.nist.gov/cuu/Units/binary.html">IEC 60027-2 prefixes for binary multiples</a>.
  4057.  
  4058.    <p>The following suffixes are defined.  Large sizes like <code>1Y</code> may be
  4059. rejected by your computer due to limitations of its arithmetic.
  4060.  
  4061.      <dl>
  4062. <dt>`<samp><span class="samp">kB</span></samp>'<dd><a name="index-kilobyte_002c-definition-of-129"></a>kilobyte: 10^3 = 1000. 
  4063. <br><dt>`<samp><span class="samp">k</span></samp>'<dt>`<samp><span class="samp">K</span></samp>'<dt>`<samp><span class="samp">KiB</span></samp>'<dd><a name="index-kibibyte_002c-definition-of-130"></a>kibibyte: 2^10 = 1024.  `<samp><span class="samp">K</span></samp>' is special: the SI prefix is
  4064. `<samp><span class="samp">k</span></samp>' and the IEC 60027-2 prefix is `<samp><span class="samp">Ki</span></samp>', but tradition and
  4065. <span class="sc">posix</span> use `<samp><span class="samp">k</span></samp>' to mean `<samp><span class="samp">KiB</span></samp>'. 
  4066. <br><dt>`<samp><span class="samp">MB</span></samp>'<dd><a name="index-megabyte_002c-definition-of-131"></a>megabyte: 10^6 = 1,000,000. 
  4067. <br><dt>`<samp><span class="samp">M</span></samp>'<dt>`<samp><span class="samp">MiB</span></samp>'<dd><a name="index-mebibyte_002c-definition-of-132"></a>mebibyte: 2^20 = 1,048,576. 
  4068. <br><dt>`<samp><span class="samp">GB</span></samp>'<dd><a name="index-gigabyte_002c-definition-of-133"></a>gigabyte: 10^9 = 1,000,000,000. 
  4069. <br><dt>`<samp><span class="samp">G</span></samp>'<dt>`<samp><span class="samp">GiB</span></samp>'<dd><a name="index-gibibyte_002c-definition-of-134"></a>gibibyte: 2^30 = 1,073,741,824. 
  4070. <br><dt>`<samp><span class="samp">TB</span></samp>'<dd><a name="index-terabyte_002c-definition-of-135"></a>terabyte:  10^12 = 1,000,000,000,000. 
  4071. <br><dt>`<samp><span class="samp">T</span></samp>'<dt>`<samp><span class="samp">TiB</span></samp>'<dd><a name="index-tebibyte_002c-definition-of-136"></a>tebibyte: 2^40 = 1,099,511,627,776. 
  4072. <br><dt>`<samp><span class="samp">PB</span></samp>'<dd><a name="index-petabyte_002c-definition-of-137"></a>petabyte: 10^15 = 1,000,000,000,000,000. 
  4073. <br><dt>`<samp><span class="samp">P</span></samp>'<dt>`<samp><span class="samp">PiB</span></samp>'<dd><a name="index-pebibyte_002c-definition-of-138"></a>pebibyte: 2^50 = 1,125,899,906,842,624. 
  4074. <br><dt>`<samp><span class="samp">EB</span></samp>'<dd><a name="index-exabyte_002c-definition-of-139"></a>exabyte: 10^18 = 1,000,000,000,000,000,000. 
  4075. <br><dt>`<samp><span class="samp">E</span></samp>'<dt>`<samp><span class="samp">EiB</span></samp>'<dd><a name="index-exbibyte_002c-definition-of-140"></a>exbibyte: 2^60 = 1,152,921,504,606,846,976. 
  4076. <br><dt>`<samp><span class="samp">ZB</span></samp>'<dd><a name="index-zettabyte_002c-definition-of-141"></a>zettabyte: 10^21 = 1,000,000,000,000,000,000,000
  4077. <br><dt>`<samp><span class="samp">Z</span></samp>'<dt>`<samp><span class="samp">ZiB</span></samp>'<dd>2^70 = 1,180,591,620,717,411,303,424. 
  4078. (`<samp><span class="samp">Zi</span></samp>' is a GNU extension to IEC 60027-2.) 
  4079. <br><dt>`<samp><span class="samp">YB</span></samp>'<dd><a name="index-yottabyte_002c-definition-of-142"></a>yottabyte: 10^24 = 1,000,000,000,000,000,000,000,000. 
  4080. <br><dt>`<samp><span class="samp">Y</span></samp>'<dt>`<samp><span class="samp">YiB</span></samp>'<dd>2^80 = 1,208,925,819,614,629,174,706,176. 
  4081. (`<samp><span class="samp">Yi</span></samp>' is a GNU extension to IEC 60027-2.) 
  4082. </dl>
  4083.  
  4084. <div class="node">
  4085. <p><hr>
  4086. <a name="Invoking-diff"></a>
  4087. Next: <a rel="next" accesskey="n" href="#Invoking-diff3">Invoking diff3</a>,
  4088. Previous: <a rel="previous" accesskey="p" href="#Invoking-cmp">Invoking cmp</a>,
  4089. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4090.  
  4091. </div>
  4092.  
  4093. <h2 class="chapter">13 Invoking <samp><span class="command">diff</span></samp></h2>
  4094.  
  4095. <p><a name="index-invoking-_0040command_007bdiff_007d-143"></a><a name="index-g_t_0040command_007bdiff_007d-invocation-144"></a>
  4096. The format for running the <samp><span class="command">diff</span></samp> command is:
  4097.  
  4098. <pre class="example">     diff <var>options</var>... <var>files</var>...
  4099. </pre>
  4100.    <p>In the simplest case, two file names <var>from-file</var> and
  4101. <var>to-file</var> are given, and <samp><span class="command">diff</span></samp> compares the contents of
  4102. <var>from-file</var> and <var>to-file</var>.  A file name of <samp><span class="file">-</span></samp> stands for
  4103. text read from the standard input.  As a special case, `<samp><span class="samp">diff - -</span></samp>'
  4104. compares a copy of standard input to itself.
  4105.  
  4106.    <p>If one file is a directory and the other is not, <samp><span class="command">diff</span></samp> compares
  4107. the file in the directory whose name is that of the non-directory. 
  4108. The non-directory file must not be <samp><span class="file">-</span></samp>.
  4109.  
  4110.    <p>If two file names are given and both are directories,
  4111. <samp><span class="command">diff</span></samp> compares corresponding files in both directories, in
  4112. alphabetical order; this comparison is not recursive unless the
  4113. <samp><span class="option">-r</span></samp> or <samp><span class="option">--recursive</span></samp> option is given.  <samp><span class="command">diff</span></samp> never
  4114. compares the actual contents of a directory as if it were a file.  The
  4115. file that is fully specified may not be standard input, because standard
  4116. input is nameless and the notion of “file with the same name” does not
  4117. apply.
  4118.  
  4119.    <p>If the <samp><span class="option">--from-file=</span><var>file</var></samp> option is given, the number of
  4120. file names is arbitrary, and <var>file</var> is compared to each named file. 
  4121. Similarly, if the <samp><span class="option">--to-file=</span><var>file</var></samp> option is given, each
  4122. named file is compared to <var>file</var>.
  4123.  
  4124.    <p><samp><span class="command">diff</span></samp> options begin with `<samp><span class="samp">-</span></samp>', so normally file names
  4125. may not begin with `<samp><span class="samp">-</span></samp>'.  However, <samp><span class="option">--</span></samp> as an
  4126. argument by itself treats the remaining arguments as file names even if
  4127. they begin with `<samp><span class="samp">-</span></samp>'.
  4128.  
  4129.    <p>An exit status of 0 means no differences were found, 1 means some
  4130. differences were found, and 2 means trouble.
  4131.  
  4132. <ul class="menu">
  4133. <li><a accesskey="1" href="#diff-Options">diff Options</a>:  Summary of options to <samp><span class="command">diff</span></samp>. 
  4134. </ul>
  4135.  
  4136. <div class="node">
  4137. <p><hr>
  4138. <a name="diff-Options"></a>
  4139. Up: <a rel="up" accesskey="u" href="#Invoking-diff">Invoking diff</a>
  4140.  
  4141. </div>
  4142.  
  4143. <h3 class="section">13.1 Options to <samp><span class="command">diff</span></samp></h3>
  4144.  
  4145. <p><a name="index-g_t_0040command_007bdiff_007d-options-145"></a><a name="index-options-for-_0040command_007bdiff_007d-146"></a>
  4146. Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> accepts. 
  4147. Most options have two equivalent names, one of which is a single letter
  4148. preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name preceded by
  4149. `<samp><span class="samp">--</span></samp>'.  Multiple single letter options (unless they take an
  4150. argument) can be combined into a single command line word: <samp><span class="option">-ac</span></samp> is
  4151. equivalent to <samp><span class="option">-a -c</span></samp>.  Long named options can be abbreviated to
  4152. any unique prefix of their name.  Brackets ([ and ]) indicate that an
  4153. option takes an optional argument.
  4154.  
  4155.      <dl>
  4156. <dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
  4157. do not seem to be text.  See <a href="#Binary">Binary</a>.
  4158.  
  4159.      <br><dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--ignore-space-change</span></samp><dd>Ignore changes in amount of white space.  See <a href="#White-Space">White Space</a>.
  4160.  
  4161.      <br><dt><samp><span class="option">-B</span></samp><dt><samp><span class="option">--ignore-blank-lines</span></samp><dd>Ignore changes that just insert or delete blank lines.  See <a href="#Blank-Lines">Blank Lines</a>.
  4162.  
  4163.      <br><dt><samp><span class="option">--binary</span></samp><dd>Read and write data in binary mode.  See <a href="#Binary">Binary</a>.
  4164.  
  4165.      <br><dt><samp><span class="option">-c</span></samp><dd>Use the context output format, showing three lines of context. 
  4166. See <a href="#Context-Format">Context Format</a>.
  4167.  
  4168.      <br><dt><samp><span class="option">-C </span><var>lines</var></samp><dt><samp><span class="option">--context[=</span><var>lines</var><span class="option">]</span></samp><dd>Use the context output format, showing <var>lines</var> (an integer) lines of
  4169. context, or three if <var>lines</var> is not given.  See <a href="#Context-Format">Context Format</a>. 
  4170. For proper operation, <samp><span class="command">patch</span></samp> typically needs at least two lines of
  4171. context.
  4172.  
  4173.      <p>On older systems, <samp><span class="command">diff</span></samp> supports an obsolete option
  4174. <samp><span class="option">-</span><var>lines</var></samp> that has effect when combined with <samp><span class="option">-c</span></samp>
  4175. or <samp><span class="option">-p</span></samp>.  <span class="sc">posix</span> 1003.1-2001 (see <a href="#Standards-conformance">Standards conformance</a>) does not allow this; use <samp><span class="option">-C </span><var>lines</var></samp>
  4176. instead.
  4177.  
  4178.      <br><dt><samp><span class="option">--changed-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line group containing differing lines from
  4179. both files in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.
  4180.  
  4181.      <br><dt><samp><span class="option">-d</span></samp><dt><samp><span class="option">--minimal</span></samp><dd>Change the algorithm perhaps find a smaller set of changes.  This makes
  4182. <samp><span class="command">diff</span></samp> slower (sometimes much slower).  See <a href="#diff-Performance">diff Performance</a>.
  4183.  
  4184.      <br><dt><samp><span class="option">-D </span><var>name</var></samp><dt><samp><span class="option">--ifdef=</span><var>name</var></samp><dd>Make merged `<samp><span class="samp">#ifdef</span></samp>' format output, conditional on the preprocessor
  4185. macro <var>name</var>.  See <a href="#If_002dthen_002delse">If-then-else</a>.
  4186.  
  4187.      <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Make output that is a valid <samp><span class="command">ed</span></samp> script.  See <a href="#ed-Scripts">ed Scripts</a>.
  4188.  
  4189.      <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--ignore-tab-expansion</span></samp><dd>Ignore changes due to tab expansion. 
  4190. See <a href="#White-Space">White Space</a>.
  4191.  
  4192.      <br><dt><samp><span class="option">-f</span></samp><dt><samp><span class="option">--forward-ed</span></samp><dd>Make output that looks vaguely like an <samp><span class="command">ed</span></samp> script but has changes
  4193. in the order they appear in the file.  See <a href="#Forward-ed">Forward ed</a>.
  4194.  
  4195.      <br><dt><samp><span class="option">-F </span><var>regexp</var></samp><dt><samp><span class="option">--show-function-line=</span><var>regexp</var></samp><dd>In context and unified format, for each hunk of differences, show some
  4196. of the last preceding line that matches <var>regexp</var>.  See <a href="#Specified-Headings">Specified Headings</a>.
  4197.  
  4198.      <br><dt><samp><span class="option">--from-file=</span><var>file</var></samp><dd>Compare <var>file</var> to each operand; <var>file</var> may be a directory.
  4199.  
  4200.      <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
  4201.  
  4202.      <br><dt><samp><span class="option">--horizon-lines=</span><var>lines</var></samp><dd>Do not discard the last <var>lines</var> lines of the common prefix
  4203. and the first <var>lines</var> lines of the common suffix. 
  4204. See <a href="#diff-Performance">diff Performance</a>.
  4205.  
  4206.      <br><dt><samp><span class="option">-i</span></samp><dt><samp><span class="option">--ignore-case</span></samp><dd>Ignore changes in case; consider upper- and lower-case letters
  4207. equivalent.  See <a href="#Case-Folding">Case Folding</a>.
  4208.  
  4209.      <br><dt><samp><span class="option">-I </span><var>regexp</var></samp><dt><samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp><dd>Ignore changes that just insert or delete lines that match <var>regexp</var>. 
  4210. See <a href="#Specified-Folding">Specified Folding</a>.
  4211.  
  4212.      <br><dt><samp><span class="option">--ignore-file-name-case</span></samp><dd>Ignore case when comparing file names during recursive comparison. 
  4213. See <a href="#Comparing-Directories">Comparing Directories</a>.
  4214.  
  4215.      <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--paginate</span></samp><dd>Pass the output through <samp><span class="command">pr</span></samp> to paginate it.  See <a href="#Pagination">Pagination</a>.
  4216.  
  4217.      <br><dt><samp><span class="option">--label=</span><var>label</var></samp><dd>Use <var>label</var> instead of the file name in the context format
  4218. (see <a href="#Context-Format">Context Format</a>) and unified format (see <a href="#Unified-Format">Unified Format</a>)
  4219. headers.  See <a href="#RCS">RCS</a>.
  4220.  
  4221.      <br><dt><samp><span class="option">--left-column</span></samp><dd>Print only the left column of two common lines in side by side format. 
  4222. See <a href="#Side-by-Side-Format">Side by Side Format</a>.
  4223.  
  4224.      <br><dt><samp><span class="option">--line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output all input lines in if-then-else format. 
  4225. See <a href="#Line-Formats">Line Formats</a>.
  4226.  
  4227.      <br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--rcs</span></samp><dd>Output <span class="sc">rcs</span>-format diffs; like <samp><span class="option">-f</span></samp> except that each command
  4228. specifies the number of lines affected.  See <a href="#RCS">RCS</a>.
  4229.  
  4230.      <br><dt><samp><span class="option">-N</span></samp><dt><samp><span class="option">--new-file</span></samp><dd>In directory comparison, if a file is found in only one directory,
  4231. treat it as present but empty in the other directory.  See <a href="#Comparing-Directories">Comparing Directories</a>.
  4232.  
  4233.      <br><dt><samp><span class="option">--new-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of lines taken from just the second
  4234. file in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.
  4235.  
  4236.      <br><dt><samp><span class="option">--new-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line taken from just the second file in
  4237. if-then-else format.  See <a href="#Line-Formats">Line Formats</a>.
  4238.  
  4239.      <br><dt><samp><span class="option">--old-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of lines taken from just the first
  4240. file in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.
  4241.  
  4242.      <br><dt><samp><span class="option">--old-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line taken from just the first file in
  4243. if-then-else format.  See <a href="#Line-Formats">Line Formats</a>.
  4244.  
  4245.      <br><dt><samp><span class="option">-p</span></samp><dt><samp><span class="option">--show-c-function</span></samp><dd>Show which C function each change is in.  See <a href="#C-Function-Headings">C Function Headings</a>.
  4246.  
  4247.      <br><dt><samp><span class="option">-q</span></samp><dt><samp><span class="option">--brief</span></samp><dd>Report only whether the files differ, not the details of the
  4248. differences.  See <a href="#Brief">Brief</a>.
  4249.  
  4250.      <br><dt><samp><span class="option">-r</span></samp><dt><samp><span class="option">--recursive</span></samp><dd>When comparing directories, recursively compare any subdirectories
  4251. found.  See <a href="#Comparing-Directories">Comparing Directories</a>.
  4252.  
  4253.      <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--report-identical-files</span></samp><dd>Report when two files are the same.  See <a href="#Comparing-Directories">Comparing Directories</a>.
  4254.  
  4255.      <br><dt><samp><span class="option">-S </span><var>file</var></samp><dt><samp><span class="option">--starting-file=</span><var>file</var></samp><dd>When comparing directories, start with the file <var>file</var>.  This is
  4256. used for resuming an aborted comparison.  See <a href="#Comparing-Directories">Comparing Directories</a>.
  4257.  
  4258.      <br><dt><samp><span class="option">--speed-large-files</span></samp><dd>Use heuristics to speed handling of large files that have numerous
  4259. scattered small changes.  See <a href="#diff-Performance">diff Performance</a>.
  4260.  
  4261.      <br><dt><samp><span class="option">--strip-trailing-cr</span></samp><dd>Strip any trailing carriage return at the end of an input line. 
  4262. See <a href="#Binary">Binary</a>.
  4263.  
  4264.      <br><dt><samp><span class="option">--suppress-common-lines</span></samp><dd>Do not print common lines in side by side format. 
  4265. See <a href="#Side-by-Side-Format">Side by Side Format</a>.
  4266.  
  4267.      <br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--expand-tabs</span></samp><dd>Expand tabs to spaces in the output, to preserve the alignment of tabs
  4268. in the input files.  See <a href="#Tabs">Tabs</a>.
  4269.  
  4270.      <br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--initial-tab</span></samp><dd>Output a tab rather than a space before the text of a line in normal or
  4271. context format.  This causes the alignment of tabs in the line to look
  4272. normal.  See <a href="#Tabs">Tabs</a>.
  4273.  
  4274.      <br><dt><samp><span class="option">--to-file=</span><var>file</var></samp><dd>Compare each operand to <var>file</var>; <var>file</var> may be a directory.
  4275.  
  4276.      <br><dt><samp><span class="option">-u</span></samp><dd>Use the unified output format, showing three lines of context. 
  4277. See <a href="#Unified-Format">Unified Format</a>.
  4278.  
  4279.      <br><dt><samp><span class="option">--unchanged-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of common lines taken from both files
  4280. in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.
  4281.  
  4282.      <br><dt><samp><span class="option">--unchanged-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line common to both files in if-then-else
  4283. format.  See <a href="#Line-Formats">Line Formats</a>.
  4284.  
  4285.      <br><dt><samp><span class="option">--unidirectional-new-file</span></samp><dd>When comparing directories, if a file appears only in the second
  4286. directory of the two, treat it as present but empty in the other. 
  4287. See <a href="#Comparing-Directories">Comparing Directories</a>.
  4288.  
  4289.      <br><dt><samp><span class="option">-U </span><var>lines</var></samp><dt><samp><span class="option">--unified[=</span><var>lines</var><span class="option">]</span></samp><dd>Use the unified output format, showing <var>lines</var> (an integer) lines of
  4290. context, or three if <var>lines</var> is not given.  See <a href="#Unified-Format">Unified Format</a>. 
  4291. For proper operation, <samp><span class="command">patch</span></samp> typically needs at least two lines of
  4292. context.
  4293.  
  4294.      <p>On older systems, <samp><span class="command">diff</span></samp> supports an obsolete option
  4295. <samp><span class="option">-</span><var>lines</var></samp> that has effect when combined with <samp><span class="option">-u</span></samp>. 
  4296. <span class="sc">posix</span> 1003.1-2001 (see <a href="#Standards-conformance">Standards conformance</a>) does not allow
  4297. this; use <samp><span class="option">-U </span><var>lines</var></samp> instead.
  4298.  
  4299.      <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
  4300.  
  4301.      <br><dt><samp><span class="option">-w</span></samp><dt><samp><span class="option">--ignore-all-space</span></samp><dd>Ignore white space when comparing lines.  See <a href="#White-Space">White Space</a>.
  4302.  
  4303.      <br><dt><samp><span class="option">-W </span><var>columns</var></samp><dt><samp><span class="option">--width=</span><var>columns</var></samp><dd>Output at most <var>columns</var> (default 130) print columns per line in
  4304. side by side format.  See <a href="#Side-by-Side-Format">Side by Side Format</a>.
  4305.  
  4306.      <br><dt><samp><span class="option">-x </span><var>pattern</var></samp><dt><samp><span class="option">--exclude=</span><var>pattern</var></samp><dd>When comparing directories, ignore files and subdirectories whose basenames
  4307. match <var>pattern</var>.  See <a href="#Comparing-Directories">Comparing Directories</a>.
  4308.  
  4309.      <br><dt><samp><span class="option">-X </span><var>file</var></samp><dt><samp><span class="option">--exclude-from=</span><var>file</var></samp><dd>When comparing directories, ignore files and subdirectories whose basenames
  4310. match any pattern contained in <var>file</var>.  See <a href="#Comparing-Directories">Comparing Directories</a>.
  4311.  
  4312.      <br><dt><samp><span class="option">-y</span></samp><dt><samp><span class="option">--side-by-side</span></samp><dd>Use the side by side output format.  See <a href="#Side-by-Side-Format">Side by Side Format</a>. 
  4313. </dl>
  4314.  
  4315. <div class="node">
  4316. <p><hr>
  4317. <a name="Invoking-diff3"></a>
  4318. Next: <a rel="next" accesskey="n" href="#Invoking-patch">Invoking patch</a>,
  4319. Previous: <a rel="previous" accesskey="p" href="#Invoking-diff">Invoking diff</a>,
  4320. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4321.  
  4322. </div>
  4323.  
  4324. <h2 class="chapter">14 Invoking <samp><span class="command">diff3</span></samp></h2>
  4325.  
  4326. <p><a name="index-invoking-_0040command_007bdiff3_007d-147"></a><a name="index-g_t_0040command_007bdiff3_007d-invocation-148"></a>
  4327. The <samp><span class="command">diff3</span></samp> command compares three files and outputs descriptions
  4328. of their differences.  Its arguments are as follows:
  4329.  
  4330. <pre class="example">     diff3 <var>options</var>... <var>mine</var> <var>older</var> <var>yours</var>
  4331. </pre>
  4332.    <p>The files to compare are <var>mine</var>, <var>older</var>, and <var>yours</var>. 
  4333. At most one of these three file names may be <samp><span class="file">-</span></samp>,
  4334. which tells <samp><span class="command">diff3</span></samp> to read the standard input for that file.
  4335.  
  4336.    <p>An exit status of 0 means <samp><span class="command">diff3</span></samp> was successful, 1 means some
  4337. conflicts were found, and 2 means trouble.
  4338.  
  4339. <ul class="menu">
  4340. <li><a accesskey="1" href="#diff3-Options">diff3 Options</a>:  Summary of options to <samp><span class="command">diff3</span></samp>. 
  4341. </ul>
  4342.  
  4343. <div class="node">
  4344. <p><hr>
  4345. <a name="diff3-Options"></a>
  4346. Up: <a rel="up" accesskey="u" href="#Invoking-diff3">Invoking diff3</a>
  4347.  
  4348. </div>
  4349.  
  4350. <h3 class="section">14.1 Options to <samp><span class="command">diff3</span></samp></h3>
  4351.  
  4352. <p><a name="index-g_t_0040command_007bdiff3_007d-options-149"></a><a name="index-options-for-_0040command_007bdiff3_007d-150"></a>
  4353. Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">diff3</span></samp>
  4354. accepts.  Multiple single letter options (unless they take an argument)
  4355. can be combined into a single command line argument.
  4356.  
  4357.      <dl>
  4358. <dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
  4359. do not appear to be text.  See <a href="#Binary">Binary</a>.
  4360.  
  4361.      <br><dt><samp><span class="option">-A</span></samp><dt><samp><span class="option">--show-all</span></samp><dd>Incorporate all unmerged changes from <var>older</var> to <var>yours</var> into
  4362. <var>mine</var>, surrounding conflicts with bracket lines. 
  4363. See <a href="#Marking-Conflicts">Marking Conflicts</a>.
  4364.  
  4365.      <br><dt><samp><span class="option">--diff-program=</span><var>program</var></samp><dd>Use the compatible comparison program <var>program</var> to compare files
  4366. instead of <samp><span class="command">diff</span></samp>.
  4367.  
  4368.      <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Generate an <samp><span class="command">ed</span></samp> script that incorporates all the changes from
  4369. <var>older</var> to <var>yours</var> into <var>mine</var>.  See <a href="#Which-Changes">Which Changes</a>.
  4370.  
  4371.      <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--show-overlap</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except bracket lines from overlapping changes' first
  4372. and third files. 
  4373. See <a href="#Marking-Conflicts">Marking Conflicts</a>. 
  4374. With <samp><span class="option">-E</span></samp>, an overlapping change looks like this:
  4375.  
  4376.      <pre class="example">          <<<<<<< <var>mine</var>
  4377.           <span class="roman">lines from </span><var>mine</var>
  4378.           =======
  4379.           <span class="roman">lines from </span><var>yours</var>
  4380.           >>>>>>> <var>yours</var>
  4381.      </pre>
  4382.      <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
  4383.  
  4384.      <br><dt><samp><span class="option">-i</span></samp><dd>Generate `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>' commands at the end of the <samp><span class="command">ed</span></samp>
  4385. script for System V compatibility.  This option must be combined with
  4386. one of the <samp><span class="option">-AeExX3</span></samp> options, and may not be combined with <samp><span class="option">-m</span></samp>. 
  4387. See <a href="#Saving-the-Changed-File">Saving the Changed File</a>.
  4388.  
  4389.      <br><dt><samp><span class="option">-L </span><var>label</var></samp><dt><samp><span class="option">--label=</span><var>label</var></samp><dd>Use the label <var>label</var> for the brackets output by the <samp><span class="option">-A</span></samp>,
  4390. <samp><span class="option">-E</span></samp> and <samp><span class="option">-X</span></samp> options.  This option may be given up to three
  4391. times, one for each input file.  The default labels are the names of
  4392. the input files.  Thus `<samp><span class="samp">diff3 -L X -L Y -L Z -m A B C</span></samp>' acts like
  4393. `<samp><span class="samp">diff3 -m A B C</span></samp>', except that the output looks like it came from
  4394. files named `<samp><span class="samp">X</span></samp>', `<samp><span class="samp">Y</span></samp>' and `<samp><span class="samp">Z</span></samp>' rather than from files
  4395. named `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>' and `<samp><span class="samp">C</span></samp>'.  See <a href="#Marking-Conflicts">Marking Conflicts</a>.
  4396.  
  4397.      <br><dt><samp><span class="option">-m</span></samp><dt><samp><span class="option">--merge</span></samp><dd>Apply the edit script to the first file and send the result to standard
  4398. output.  Unlike piping the output from <samp><span class="command">diff3</span></samp> to <samp><span class="command">ed</span></samp>, this
  4399. works even for binary files and incomplete lines.  <samp><span class="option">-A</span></samp> is assumed
  4400. if no edit script option is specified.  See <a href="#Bypassing-ed">Bypassing ed</a>.
  4401.  
  4402.      <br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--initial-tab</span></samp><dd>Output a tab rather than two spaces before the text of a line in normal format. 
  4403. This causes the alignment of tabs in the line to look normal.  See <a href="#Tabs">Tabs</a>.
  4404.  
  4405.      <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
  4406.  
  4407.      <br><dt><samp><span class="option">-x</span></samp><dt><samp><span class="option">--overlap-only</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except output only the overlapping changes. 
  4408. See <a href="#Which-Changes">Which Changes</a>.
  4409.  
  4410.      <br><dt><samp><span class="option">-X</span></samp><dd>Like <samp><span class="option">-E</span></samp>, except output only the overlapping changes. 
  4411. In other words, like <samp><span class="option">-x</span></samp>, except bracket changes as in <samp><span class="option">-E</span></samp>. 
  4412. See <a href="#Marking-Conflicts">Marking Conflicts</a>.
  4413.  
  4414.      <br><dt><samp><span class="option">-3</span></samp><dt><samp><span class="option">--easy-only</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except output only the nonoverlapping changes. 
  4415. See <a href="#Which-Changes">Which Changes</a>. 
  4416. </dl>
  4417.  
  4418. <div class="node">
  4419. <p><hr>
  4420. <a name="Invoking-patch"></a>
  4421. Next: <a rel="next" accesskey="n" href="#Invoking-sdiff">Invoking sdiff</a>,
  4422. Previous: <a rel="previous" accesskey="p" href="#Invoking-diff3">Invoking diff3</a>,
  4423. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4424.  
  4425. </div>
  4426.  
  4427. <h2 class="chapter">15 Invoking <samp><span class="command">patch</span></samp></h2>
  4428.  
  4429. <p><a name="index-invoking-_0040command_007bpatch_007d-151"></a><a name="index-g_t_0040command_007bpatch_007d-invocation-152"></a>
  4430. Normally <samp><span class="command">patch</span></samp> is invoked like this:
  4431.  
  4432. <pre class="example">     patch <<var>patchfile</var>
  4433. </pre>
  4434.    <p>The full format for invoking <samp><span class="command">patch</span></samp> is:
  4435.  
  4436. <pre class="example">     patch <var>options</var>... <span class="roman">[</span><var>origfile</var> <span class="roman">[</span><var>patchfile</var><span class="roman">]</span><span class="roman">]</span>
  4437. </pre>
  4438.    <p>You can also specify where to read the patch from with the <samp><span class="option">-i
  4439. </span><var>patchfile</var></samp> or <samp><span class="option">--input=</span><var>patchfile</var></samp> option. 
  4440. If you do not specify <var>patchfile</var>, or if <var>patchfile</var> is
  4441. <samp><span class="file">-</span></samp>, <samp><span class="command">patch</span></samp> reads the patch (that is, the <samp><span class="command">diff</span></samp> output)
  4442. from the standard input.
  4443.  
  4444.    <p>If you do not specify an input file on the command line, <samp><span class="command">patch</span></samp>
  4445. tries to intuit from the <dfn>leading text</dfn> (any text in the patch
  4446. that comes before the <samp><span class="command">diff</span></samp> output) which file to edit. 
  4447. See <a href="#Multiple-Patches">Multiple Patches</a>.
  4448.  
  4449.    <p>By default, <samp><span class="command">patch</span></samp> replaces the original input file with the
  4450. patched version, possibly after renaming the original file into a
  4451. backup file (see <a href="#Backup-Names">Backup Names</a>, for a description of how
  4452. <samp><span class="command">patch</span></samp> names backup files).  You can also specify where to
  4453. put the output with the <samp><span class="option">-o </span><var>file</var></samp> or
  4454. <samp><span class="option">--output=</span><var>file</var></samp> option; however, do not use this option
  4455. if <var>file</var> is one of the input files.
  4456.  
  4457. <ul class="menu">
  4458. <li><a accesskey="1" href="#patch-Options">patch Options</a>:      Summary table of options to <samp><span class="command">patch</span></samp>. 
  4459. </ul>
  4460.  
  4461. <div class="node">
  4462. <p><hr>
  4463. <a name="patch-Options"></a>
  4464. Up: <a rel="up" accesskey="u" href="#Invoking-patch">Invoking patch</a>
  4465.  
  4466. </div>
  4467.  
  4468. <h3 class="section">15.1 Options to <samp><span class="command">patch</span></samp></h3>
  4469.  
  4470. <p><a name="index-g_t_0040command_007bpatch_007d-options-153"></a><a name="index-options-for-_0040command_007bpatch_007d-154"></a>
  4471. Here is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>
  4472. accepts.  See <a href="#patch-and-Tradition">patch and Tradition</a>, for which of these options are
  4473. safe to use in older versions of <samp><span class="command">patch</span></samp>.
  4474.  
  4475.    <p>Multiple single-letter options that do not take an argument can be
  4476. combined into a single command line argument with only one dash.
  4477.  
  4478.      <dl>
  4479. <dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--backup</span></samp><dd>Back up the original contents of each file, even if backups would
  4480. normally not be made.  See <a href="#Backups">Backups</a>.
  4481.  
  4482.      <br><dt><samp><span class="option">-B </span><var>prefix</var></samp><dt><samp><span class="option">--prefix=</span><var>prefix</var></samp><dd>Prepend <var>prefix</var> to backup file names.  See <a href="#Backup-Names">Backup Names</a>.
  4483.  
  4484.      <br><dt><samp><span class="option">--backup-if-mismatch</span></samp><dd>Back up the original contents of each file if the patch does not
  4485. exactly match the file.  This is the default behavior when not
  4486. conforming to <span class="sc">posix</span>.  See <a href="#Backups">Backups</a>.
  4487.  
  4488.      <br><dt><samp><span class="option">--binary</span></samp><dd>Read and write all files in binary mode, except for standard output
  4489. and <samp><span class="file">/dev/tty</span></samp>.  This option has no effect on
  4490. <span class="sc">posix</span>-conforming systems like <span class="sc">gnu</span>/Linux.  On systems where
  4491. this option makes a difference, the patch should be generated by
  4492. `<samp><span class="samp">diff -a --binary</span></samp>'.  See <a href="#Binary">Binary</a>.
  4493.  
  4494.      <br><dt><samp><span class="option">-c</span></samp><dt><samp><span class="option">--context</span></samp><dd>Interpret the patch file as a context diff.  See <a href="#patch-Input">patch Input</a>.
  4495.  
  4496.      <br><dt><samp><span class="option">-d </span><var>directory</var></samp><dt><samp><span class="option">--directory=</span><var>directory</var></samp><dd>Make directory <var>directory</var> the current directory for interpreting
  4497. both file names in the patch file, and file names given as arguments to
  4498. other options.  See <a href="#patch-Directories">patch Directories</a>.
  4499.  
  4500.      <br><dt><samp><span class="option">-D </span><var>name</var></samp><dt><samp><span class="option">--ifdef=</span><var>name</var></samp><dd>Make merged if-then-else output using <var>name</var>.  See <a href="#If_002dthen_002delse">If-then-else</a>.
  4501.  
  4502.      <br><dt><samp><span class="option">--dry-run</span></samp><dd>Print the results of applying the patches without actually changing
  4503. any files.  See <a href="#Dry-Runs">Dry Runs</a>.
  4504.  
  4505.      <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Interpret the patch file as an <samp><span class="command">ed</span></samp> script.  See <a href="#patch-Input">patch Input</a>.
  4506.  
  4507.      <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--remove-empty-files</span></samp><dd>Remove output files that are empty after the patches have been applied. 
  4508. See <a href="#Creating-and-Removing">Creating and Removing</a>.
  4509.  
  4510.      <br><dt><samp><span class="option">-f</span></samp><dt><samp><span class="option">--force</span></samp><dd>Assume that the user knows exactly what he or she is doing, and do not
  4511. ask any questions.  See <a href="#patch-Messages">patch Messages</a>.
  4512.  
  4513.      <br><dt><samp><span class="option">-F </span><var>lines</var></samp><dt><samp><span class="option">--fuzz=</span><var>lines</var></samp><dd>Set the maximum fuzz factor to <var>lines</var>.  See <a href="#Inexact">Inexact</a>.
  4514.  
  4515.      <br><dt><samp><span class="option">-g </span><var>num</var></samp><dt><samp><span class="option">--get=</span><var>num</var></samp><dd>If <var>num</var> is positive, get input files from a revision control
  4516. system as necessary; if zero, do not get the files; if negative, ask
  4517. the user whether to get the files.  See <a href="#Revision-Control">Revision Control</a>.
  4518.  
  4519.      <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
  4520.  
  4521.      <br><dt><samp><span class="option">-i </span><var>patchfile</var></samp><dt><samp><span class="option">--input=</span><var>patchfile</var></samp><dd>Read the patch from <var>patchfile</var> rather than from standard input. 
  4522. See <a href="#patch-Options">patch Options</a>.
  4523.  
  4524.      <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--ignore-white-space</span></samp><dd>Let any sequence of blanks (spaces or tabs) in the patch file match
  4525. any sequence of blanks in the input file.  See <a href="#Changed-White-Space">Changed White Space</a>.
  4526.  
  4527.      <br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--normal</span></samp><dd>Interpret the patch file as a normal diff.  See <a href="#patch-Input">patch Input</a>.
  4528.  
  4529.      <br><dt><samp><span class="option">-N</span></samp><dt><samp><span class="option">--forward</span></samp><dd>Ignore patches that <samp><span class="command">patch</span></samp> thinks are reversed or already applied. 
  4530. See also <samp><span class="option">-R</span></samp>.  See <a href="#Reversed-Patches">Reversed Patches</a>.
  4531.  
  4532.      <br><dt><samp><span class="option">--no-backup-if-mismatch</span></samp><dd>Do not back up the original contents of files.  This is the default
  4533. behavior when conforming to <span class="sc">posix</span>.  See <a href="#Backups">Backups</a>.
  4534.  
  4535.      <br><dt><samp><span class="option">-o </span><var>file</var></samp><dt><samp><span class="option">--output=</span><var>file</var></samp><dd>Use <var>file</var> as the output file name.  See <a href="#patch-Options">patch Options</a>.
  4536.  
  4537.      <br><dt><samp><span class="option">-p</span><var>number</var></samp><dt><samp><span class="option">--strip=</span><var>number</var></samp><dd>Set the file name strip count to <var>number</var>.  See <a href="#patch-Directories">patch Directories</a>.
  4538.  
  4539.      <br><dt><samp><span class="option">--posix</span></samp><dd>Conform to <span class="sc">posix</span>, as if the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment
  4540. variable had been set.  See <a href="#patch-and-POSIX">patch and POSIX</a>.
  4541.  
  4542.      <br><dt><samp><span class="option">--quoting-style=</span><var>word</var></samp><dd>Use style <var>word</var> to quote names in diagnostics, as if the
  4543. <samp><span class="env">QUOTING_STYLE</span></samp> environment variable had been set to <var>word</var>. 
  4544. See <a href="#patch-Quoting-Style">patch Quoting Style</a>.
  4545.  
  4546.      <br><dt><samp><span class="option">-r </span><var>reject-file</var></samp><dt><samp><span class="option">--reject-file=</span><var>reject-file</var></samp><dd>Use <var>reject-file</var> as the reject file name.  See <a href="#Reject-Names">Reject Names</a>.
  4547.  
  4548.      <br><dt><samp><span class="option">-R</span></samp><dt><samp><span class="option">--reverse</span></samp><dd>Assume that this patch was created with the old and new files swapped. 
  4549. See <a href="#Reversed-Patches">Reversed Patches</a>.
  4550.  
  4551.      <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd>Work silently unless an error occurs.  See <a href="#patch-Messages">patch Messages</a>.
  4552.  
  4553.      <br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--batch</span></samp><dd>Do not ask any questions.  See <a href="#patch-Messages">patch Messages</a>.
  4554.  
  4555.      <br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--set-time</span></samp><dd>Set the modification and access times of patched files from time
  4556. stamps given in context diff headers, assuming that the context diff
  4557. headers use local time.  See <a href="#Patching-Time-Stamps">Patching Time Stamps</a>.
  4558.  
  4559.      <br><dt><samp><span class="option">-u</span></samp><dt><samp><span class="option">--unified</span></samp><dd>Interpret the patch file as a unified diff.  See <a href="#patch-Input">patch Input</a>.
  4560.  
  4561.      <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
  4562.  
  4563.      <br><dt><samp><span class="option">-V </span><var>backup-style</var></samp><dt><samp><span class="option">--version=control=</span><var>backup-style</var></samp><dd>Select the naming convention for backup file names.  See <a href="#Backup-Names">Backup Names</a>.
  4564.  
  4565.      <br><dt><samp><span class="option">--verbose</span></samp><dd>Print more diagnostics than usual.  See <a href="#patch-Messages">patch Messages</a>.
  4566.  
  4567.      <br><dt><samp><span class="option">-x </span><var>number</var></samp><dt><samp><span class="option">--debug=</span><var>number</var></samp><dd>Set internal debugging flags.  Of interest only to <samp><span class="command">patch</span></samp>
  4568. patchers.
  4569.  
  4570.      <br><dt><samp><span class="option">-Y </span><var>prefix</var></samp><dt><samp><span class="option">--basename-prefix=</span><var>prefix</var></samp><dd>Prepend <var>prefix</var> to base names of backup files.  See <a href="#Backup-Names">Backup Names</a>.
  4571.  
  4572.      <br><dt><samp><span class="option">-z </span><var>suffix</var></samp><dt><samp><span class="option">--suffix=</span><var>suffix</var></samp><dd>Use <var>suffix</var> as the backup extension instead of `<samp><span class="samp">.orig</span></samp>' or
  4573. `<samp><span class="samp">~</span></samp>'.  See <a href="#Backup-Names">Backup Names</a>.
  4574.  
  4575.      <br><dt><samp><span class="option">-Z</span></samp><dt><samp><span class="option">--set-utc</span></samp><dd>Set the modification and access times of patched files from time
  4576. stamps given in context diff headers, assuming that the context diff
  4577. headers use <span class="sc">utc</span>.  See <a href="#Patching-Time-Stamps">Patching Time Stamps</a>.
  4578.  
  4579.    </dl>
  4580.  
  4581. <div class="node">
  4582. <p><hr>
  4583. <a name="Invoking-sdiff"></a>
  4584. Next: <a rel="next" accesskey="n" href="#Standards-conformance">Standards conformance</a>,
  4585. Previous: <a rel="previous" accesskey="p" href="#Invoking-patch">Invoking patch</a>,
  4586. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4587.  
  4588. </div>
  4589.  
  4590. <h2 class="chapter">16 Invoking <samp><span class="command">sdiff</span></samp></h2>
  4591.  
  4592. <p><a name="index-invoking-_0040command_007bsdiff_007d-155"></a><a name="index-g_t_0040command_007bsdiff_007d-invocation-156"></a>
  4593. The <samp><span class="command">sdiff</span></samp> command merges two files and interactively outputs the
  4594. results.  Its arguments are as follows:
  4595.  
  4596. <pre class="example">     sdiff -o <var>outfile</var> <var>options</var>... <var>from-file</var> <var>to-file</var>
  4597. </pre>
  4598.    <p>This merges <var>from-file</var> with <var>to-file</var>, with output to <var>outfile</var>. 
  4599. If <var>from-file</var> is a directory and <var>to-file</var> is not, <samp><span class="command">sdiff</span></samp>
  4600. compares the file in <var>from-file</var> whose file name is that of <var>to-file</var>,
  4601. and vice versa.  <var>from-file</var> and <var>to-file</var> may not both be
  4602. directories.
  4603.  
  4604.    <p><samp><span class="command">sdiff</span></samp> options begin with `<samp><span class="samp">-</span></samp>', so normally <var>from-file</var>
  4605. and <var>to-file</var> may not begin with `<samp><span class="samp">-</span></samp>'.  However, <samp><span class="option">--</span></samp> as an
  4606. argument by itself treats the remaining arguments as file names even if
  4607. they begin with `<samp><span class="samp">-</span></samp>'.  You may not use <samp><span class="file">-</span></samp> as an input file.
  4608.  
  4609.    <p><samp><span class="command">sdiff</span></samp> without <samp><span class="option">-o</span></samp> (or <samp><span class="option">--output</span></samp>) produces a
  4610. side-by-side difference.  This usage is obsolete; use the <samp><span class="option">-y</span></samp>
  4611. or <samp><span class="option">--side-by-side</span></samp> option of <samp><span class="command">diff</span></samp> instead.
  4612.  
  4613.    <p>An exit status of 0 means no differences were found, 1 means some
  4614. differences were found, and 2 means trouble.
  4615.  
  4616. <ul class="menu">
  4617. <li><a accesskey="1" href="#sdiff-Options">sdiff Options</a>:  Summary of options to <samp><span class="command">diff</span></samp>. 
  4618. </ul>
  4619.  
  4620. <div class="node">
  4621. <p><hr>
  4622. <a name="sdiff-Options"></a>
  4623. Up: <a rel="up" accesskey="u" href="#Invoking-sdiff">Invoking sdiff</a>
  4624.  
  4625. </div>
  4626.  
  4627. <h3 class="section">16.1 Options to <samp><span class="command">sdiff</span></samp></h3>
  4628.  
  4629. <p><a name="index-g_t_0040command_007bsdiff_007d-options-157"></a><a name="index-options-for-_0040command_007bsdiff_007d-158"></a>
  4630. Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">sdiff</span></samp> accepts. 
  4631. Each option has two equivalent names, one of which is a single
  4632. letter preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name
  4633. preceded by `<samp><span class="samp">--</span></samp>'.  Multiple single letter options (unless they take
  4634. an argument) can be combined into a single command line argument.  Long
  4635. named options can be abbreviated to any unique prefix of their name.
  4636.  
  4637.      <dl>
  4638. <dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
  4639. do not appear to be text.  See <a href="#Binary">Binary</a>.
  4640.  
  4641.      <br><dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--ignore-space-change</span></samp><dd>Ignore changes in amount of white space.  See <a href="#White-Space">White Space</a>.
  4642.  
  4643.      <br><dt><samp><span class="option">-B</span></samp><dt><samp><span class="option">--ignore-blank-lines</span></samp><dd>Ignore changes that just insert or delete blank lines.  See <a href="#Blank-Lines">Blank Lines</a>.
  4644.  
  4645.      <br><dt><samp><span class="option">-d</span></samp><dt><samp><span class="option">--minimal</span></samp><dd>Change the algorithm to perhaps find a smaller set of changes.  This
  4646. makes <samp><span class="command">sdiff</span></samp> slower (sometimes much slower).  See <a href="#diff-Performance">diff Performance</a>.
  4647.  
  4648.      <br><dt><samp><span class="option">--diff-program=</span><var>program</var></samp><dd>Use the compatible comparison program <var>program</var> to compare files
  4649. instead of <samp><span class="command">diff</span></samp>.
  4650.  
  4651.      <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--ignore-tab-expansion</span></samp><dd>Ignore changes due to tab expansion. 
  4652. See <a href="#White-Space">White Space</a>.
  4653.  
  4654.      <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
  4655.  
  4656.      <br><dt><samp><span class="option">-i</span></samp><dt><samp><span class="option">--ignore-case</span></samp><dd>Ignore changes in case; consider upper- and lower-case to be the same. 
  4657. See <a href="#Case-Folding">Case Folding</a>.
  4658.  
  4659.      <br><dt><samp><span class="option">-I </span><var>regexp</var></samp><dt><samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp><dd>Ignore changes that just insert or delete lines that match <var>regexp</var>. 
  4660. See <a href="#Specified-Folding">Specified Folding</a>.
  4661.  
  4662.      <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--left-column</span></samp><dd>Print only the left column of two common lines. 
  4663. See <a href="#Side-by-Side-Format">Side by Side Format</a>.
  4664.  
  4665.      <br><dt><samp><span class="option">-o </span><var>file</var></samp><dt><samp><span class="option">--output=</span><var>file</var></samp><dd>Put merged output into <var>file</var>.  This option is required for merging.
  4666.  
  4667.      <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--suppress-common-lines</span></samp><dd>Do not print common lines.  See <a href="#Side-by-Side-Format">Side by Side Format</a>.
  4668.  
  4669.      <br><dt><samp><span class="option">--speed-large-files</span></samp><dd>Use heuristics to speed handling of large files that have numerous
  4670. scattered small changes.  See <a href="#diff-Performance">diff Performance</a>.
  4671.  
  4672.      <br><dt><samp><span class="option">--strip-trailing-cr</span></samp><dd>Strip any trailing carriage return at the end of an input line. 
  4673. See <a href="#Binary">Binary</a>.
  4674.  
  4675.      <br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--expand-tabs</span></samp><dd>Expand tabs to spaces in the output, to preserve the alignment of tabs
  4676. in the input files.  See <a href="#Tabs">Tabs</a>.
  4677.  
  4678.      <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
  4679.  
  4680.      <br><dt><samp><span class="option">-w </span><var>columns</var></samp><dt><samp><span class="option">--width=</span><var>columns</var></samp><dd>Output at most <var>columns</var> (default 130) print columns per line. 
  4681. See <a href="#Side-by-Side-Format">Side by Side Format</a>.  Note that for historical reasons, this
  4682. option is <samp><span class="option">-W</span></samp> in <samp><span class="command">diff</span></samp>, <samp><span class="option">-w</span></samp> in <samp><span class="command">sdiff</span></samp>.
  4683.  
  4684.      <br><dt><samp><span class="option">-W</span></samp><dt><samp><span class="option">--ignore-all-space</span></samp><dd>Ignore white space when comparing lines.  See <a href="#White-Space">White Space</a>. 
  4685. Note that for historical reasons, this option is <samp><span class="option">-w</span></samp> in <samp><span class="command">diff</span></samp>,
  4686. <samp><span class="option">-W</span></samp> in <samp><span class="command">sdiff</span></samp>. 
  4687. </dl>
  4688.  
  4689. <div class="node">
  4690. <p><hr>
  4691. <a name="Standards-conformance"></a>
  4692. Next: <a rel="next" accesskey="n" href="#Projects">Projects</a>,
  4693. Previous: <a rel="previous" accesskey="p" href="#Invoking-sdiff">Invoking sdiff</a>,
  4694. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4695.  
  4696. </div>
  4697.  
  4698. <h2 class="chapter">17 Standards conformance</h2>
  4699.  
  4700. <p><a name="index-g_t_0040sc_007bposix_007d-159"></a>
  4701. <a name="index-POSIXLY_005fCORRECT-160"></a>In a few cases, the <span class="sc">gnu</span> utilities' default behavior is
  4702. incompatible with the <span class="sc">posix</span> standard.  To suppress these
  4703. incompatibilities, define the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment
  4704. variable.  Unless you are checking for <span class="sc">posix</span> conformance, you
  4705. probably do not need to define <samp><span class="env">POSIXLY_CORRECT</span></samp>.
  4706.  
  4707.    <p>Normally options and operands can appear in any order, and programs act
  4708. as if all the options appear before any operands.  For example,
  4709. `<samp><span class="samp">diff lao tzu -C 2</span></samp>' acts like `<samp><span class="samp">diff -C 2 lao tzu</span></samp>', since
  4710. `<samp><span class="samp">2</span></samp>' is an option-argument of <samp><span class="option">-C</span></samp>.  However, if the
  4711. <samp><span class="env">POSIXLY_CORRECT</span></samp> environment variable is set, options must appear
  4712. before operands, unless otherwise specified for a particular command.
  4713.  
  4714.    <p>Newer versions of <span class="sc">posix</span> are occasionally incompatible with older
  4715. versions.  For example, older versions of <span class="sc">posix</span> allowed the
  4716. command `<samp><span class="samp">diff -c -10</span></samp>' to have the same meaning as `<samp><span class="samp">diff -C
  4717. 10</span></samp>', but <span class="sc">posix</span> 1003.1-2001 `<samp><span class="samp">diff</span></samp>' no longer allows
  4718. digit-string options like <samp><span class="option">-10</span></samp>.
  4719.  
  4720.    <p><a name="index-g_t_005fPOSIX2_005fVERSION-161"></a>The <span class="sc">gnu</span> utilities normally conform to the version of <span class="sc">posix</span>
  4721. that is standard for your system.  To cause them to conform to a
  4722. different version of <span class="sc">posix</span>, define the <samp><span class="env">_POSIX2_VERSION</span></samp>
  4723. environment variable to a value of the form <var>yyyymm</var> specifying
  4724. the year and month the standard was adopted.  Two values are currently
  4725. supported for <samp><span class="env">_POSIX2_VERSION</span></samp>: `<samp><span class="samp">199209</span></samp>' stands for
  4726. <span class="sc">posix</span> 1003.2-1992, and `<samp><span class="samp">200112</span></samp>' stands for <span class="sc">posix</span>
  4727. 1003.1-2001.  For example, if you are running older software that
  4728. assumes an older version of <span class="sc">posix</span> and uses `<samp><span class="samp">diff -c -10</span></samp>',
  4729. you can work around the compatibility problems by setting
  4730. `<samp><span class="samp">_POSIX2_VERSION=199209</span></samp>' in your environment.
  4731.  
  4732. <div class="node">
  4733. <p><hr>
  4734. <a name="Projects"></a>
  4735. Next: <a rel="next" accesskey="n" href="#Copying-This-Manual">Copying This Manual</a>,
  4736. Previous: <a rel="previous" accesskey="p" href="#Standards-conformance">Standards conformance</a>,
  4737. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4738.  
  4739. </div>
  4740.  
  4741. <h2 class="chapter">18 Future Projects</h2>
  4742.  
  4743. <p>Here are some ideas for improving <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> and
  4744. <samp><span class="command">patch</span></samp>.  The <span class="sc">gnu</span> project has identified some
  4745. improvements as potential programming projects for volunteers.  You
  4746. can also help by reporting any bugs that you find.
  4747.  
  4748.    <p>If you are a programmer and would like to contribute something to the
  4749. <span class="sc">gnu</span> project, please consider volunteering for one of these
  4750. projects.  If you are seriously contemplating work, please write to
  4751. <a href="mailto:gnu@gnu.org">gnu@gnu.org</a> to coordinate with other volunteers.
  4752.  
  4753. <ul class="menu">
  4754. <li><a accesskey="1" href="#Shortcomings">Shortcomings</a>:  Suggested projects for improvements. 
  4755. <li><a accesskey="2" href="#Bugs">Bugs</a>:          Reporting bugs. 
  4756. </ul>
  4757.  
  4758. <div class="node">
  4759. <p><hr>
  4760. <a name="Shortcomings"></a>
  4761. Next: <a rel="next" accesskey="n" href="#Bugs">Bugs</a>,
  4762. Up: <a rel="up" accesskey="u" href="#Projects">Projects</a>
  4763.  
  4764. </div>
  4765.  
  4766. <h3 class="section">18.1 Suggested Projects for Improving <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></h3>
  4767.  
  4768. <p><a name="index-projects-for-directories-162"></a>
  4769. One should be able to use <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> to generate a patch from any
  4770. pair of directory trees, and given the patch and a copy of one such
  4771. tree, use <samp><span class="command">patch</span></samp> to generate a faithful copy of the other. 
  4772. Unfortunately, some changes to directory trees cannot be expressed using
  4773. current patch formats; also, <samp><span class="command">patch</span></samp> does not handle some of the
  4774. existing formats.  These shortcomings motivate the following suggested
  4775. projects.
  4776.  
  4777. <ul class="menu">
  4778. <li><a accesskey="1" href="#Internationalization">Internationalization</a>:  Handling multibyte and varying-width characters. 
  4779. <li><a accesskey="2" href="#Changing-Structure">Changing Structure</a>:    Handling changes to the directory structure. 
  4780. <li><a accesskey="3" href="#Special-Files">Special Files</a>:         Handling symbolic links, device special files, etc. 
  4781. <li><a accesskey="4" href="#Unusual-File-Names">Unusual File Names</a>:    Handling file names that contain unusual characters. 
  4782. <li><a accesskey="5" href="#Time-Stamp-Order">Time Stamp Order</a>:      Outputting diffs in time stamp order. 
  4783. <li><a accesskey="6" href="#Ignoring-Changes">Ignoring Changes</a>:      Ignoring certain changes while showing others. 
  4784. <li><a accesskey="7" href="#Speedups">Speedups</a>:              Improving performance. 
  4785. </ul>
  4786.  
  4787. <div class="node">
  4788. <p><hr>
  4789. <a name="Internationalization"></a>
  4790. Next: <a rel="next" accesskey="n" href="#Changing-Structure">Changing Structure</a>,
  4791. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4792.  
  4793. </div>
  4794.  
  4795. <h4 class="subsection">18.1.1 Handling Multibyte and Varying-Width Characters</h4>
  4796.  
  4797. <p><a name="index-multibyte-characters-163"></a><a name="index-varying_002dwidth-characters-164"></a>
  4798. <samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp> and <samp><span class="command">sdiff</span></samp> treat each line of
  4799. input as a string of unibyte characters.  This can mishandle multibyte
  4800. characters in some cases.  For example, when asked to ignore spaces,
  4801. <samp><span class="command">diff</span></samp> does not properly ignore a multibyte space character.
  4802.  
  4803.    <p>Also, <samp><span class="command">diff</span></samp> currently assumes that each byte is one column
  4804. wide, and this assumption is incorrect in some locales, e.g., locales
  4805. that use UTF-8 encoding.  This causes problems with the <samp><span class="option">-y</span></samp> or
  4806. <samp><span class="option">--side-by-side</span></samp> option of <samp><span class="command">diff</span></samp>.
  4807.  
  4808.    <p>These problems need to be fixed without unduly affecting the
  4809. performance of the utilities in unibyte environments.
  4810.  
  4811.    <p>The IBM GNU/Linux Technology Center Internationalization Team has
  4812. proposed some patches to support internationalized <samp><span class="command">diff</span></samp>
  4813. <a href="http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz">http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz</a>. 
  4814. Unfortunately, these patches are incomplete and are to an older
  4815. version of <samp><span class="command">diff</span></samp>, so more work needs to be done in this area.
  4816.  
  4817. <div class="node">
  4818. <p><hr>
  4819. <a name="Changing-Structure"></a>
  4820. Next: <a rel="next" accesskey="n" href="#Special-Files">Special Files</a>,
  4821. Previous: <a rel="previous" accesskey="p" href="#Internationalization">Internationalization</a>,
  4822. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4823.  
  4824. </div>
  4825.  
  4826. <h4 class="subsection">18.1.2 Handling Changes to the Directory Structure</h4>
  4827.  
  4828. <p><a name="index-directory-structure-changes-165"></a>
  4829. <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp> do not handle some changes to directory
  4830. structure.  For example, suppose one directory tree contains a directory
  4831. named `<samp><span class="samp">D</span></samp>' with some subsidiary files, and another contains a file
  4832. with the same name `<samp><span class="samp">D</span></samp>'.  `<samp><span class="samp">diff -r</span></samp>' does not output enough
  4833. information for <samp><span class="command">patch</span></samp> to transform the directory subtree into
  4834. the file.
  4835.  
  4836.    <p>There should be a way to specify that a file has been removed without
  4837. having to include its entire contents in the patch file.  There should
  4838. also be a way to tell <samp><span class="command">patch</span></samp> that a file was renamed, even if
  4839. there is no way for <samp><span class="command">diff</span></samp> to generate such information. 
  4840. There should be a way to tell <samp><span class="command">patch</span></samp> that a file's time stamp
  4841. has changed, even if its contents have not changed.
  4842.  
  4843.    <p>These problems can be fixed by extending the <samp><span class="command">diff</span></samp> output format
  4844. to represent changes in directory structure, and extending <samp><span class="command">patch</span></samp>
  4845. to understand these extensions.
  4846.  
  4847. <div class="node">
  4848. <p><hr>
  4849. <a name="Special-Files"></a>
  4850. Next: <a rel="next" accesskey="n" href="#Unusual-File-Names">Unusual File Names</a>,
  4851. Previous: <a rel="previous" accesskey="p" href="#Changing-Structure">Changing Structure</a>,
  4852. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4853.  
  4854. </div>
  4855.  
  4856. <h4 class="subsection">18.1.3 Files that are Neither Directories Nor Regular Files</h4>
  4857.  
  4858. <p><a name="index-special-files-166"></a>
  4859. Some files are neither directories nor regular files: they are unusual
  4860. files like symbolic links, device special files, named pipes, and
  4861. sockets.  Currently, <samp><span class="command">diff</span></samp> treats symbolic links like regular files;
  4862. it treats other special files like regular files if they are specified
  4863. at the top level, but simply reports their presence when comparing
  4864. directories.  This means that <samp><span class="command">patch</span></samp> cannot represent changes
  4865. to such files.  For example, if you change which file a symbolic link
  4866. points to, <samp><span class="command">diff</span></samp> outputs the difference between the two files,
  4867. instead of the change to the symbolic link.
  4868.  
  4869. <!-- This might not be a good idea; is it wise for root to install devices -->
  4870. <!-- this way? -->
  4871. <p><samp><span class="command">diff</span></samp> should optionally report changes to special files specially,
  4872. and <samp><span class="command">patch</span></samp> should be extended to understand these extensions.
  4873.  
  4874. <div class="node">
  4875. <p><hr>
  4876. <a name="Unusual-File-Names"></a>
  4877. Next: <a rel="next" accesskey="n" href="#Time-Stamp-Order">Time Stamp Order</a>,
  4878. Previous: <a rel="previous" accesskey="p" href="#Special-Files">Special Files</a>,
  4879. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4880.  
  4881. </div>
  4882.  
  4883. <h4 class="subsection">18.1.4 File Names that Contain Unusual Characters</h4>
  4884.  
  4885. <p><a name="index-file-names-with-unusual-characters-167"></a>
  4886. When a file name contains an unusual character like a newline or
  4887. white space, `<samp><span class="samp">diff -r</span></samp>' generates a patch that <samp><span class="command">patch</span></samp> cannot
  4888. parse.  The problem is with format of <samp><span class="command">diff</span></samp> output, not just with
  4889. <samp><span class="command">patch</span></samp>, because with odd enough file names one can cause
  4890. <samp><span class="command">diff</span></samp> to generate a patch that is syntactically correct but
  4891. patches the wrong files.  The format of <samp><span class="command">diff</span></samp> output should be
  4892. extended to handle all possible file names.
  4893.  
  4894. <div class="node">
  4895. <p><hr>
  4896. <a name="Time-Stamp-Order"></a>
  4897. Next: <a rel="next" accesskey="n" href="#Ignoring-Changes">Ignoring Changes</a>,
  4898. Previous: <a rel="previous" accesskey="p" href="#Unusual-File-Names">Unusual File Names</a>,
  4899. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4900.  
  4901. </div>
  4902.  
  4903. <h4 class="subsection">18.1.5 Outputting Diffs in Time Stamp Order</h4>
  4904.  
  4905. <p>Applying <samp><span class="command">patch</span></samp> to a multiple-file diff can result in files
  4906. whose time stamps are out of order.  <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> has
  4907. options to restore the time stamps of the updated files
  4908. (see <a href="#Patching-Time-Stamps">Patching Time Stamps</a>), but sometimes it is useful to generate
  4909. a patch that works even if the recipient does not have <span class="sc">gnu</span> patch,
  4910. or does not use these options.  One way to do this would be to
  4911. implement a <samp><span class="command">diff</span></samp> option to output diffs in time stamp order.
  4912.  
  4913. <div class="node">
  4914. <p><hr>
  4915. <a name="Ignoring-Changes"></a>
  4916. Next: <a rel="next" accesskey="n" href="#Speedups">Speedups</a>,
  4917. Previous: <a rel="previous" accesskey="p" href="#Time-Stamp-Order">Time Stamp Order</a>,
  4918. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4919.  
  4920. </div>
  4921.  
  4922. <h4 class="subsection">18.1.6 Ignoring Certain Changes</h4>
  4923.  
  4924. <p>It would be nice to have a feature for specifying two strings, one in
  4925. <var>from-file</var> and one in <var>to-file</var>, which should be considered to
  4926. match.  Thus, if the two strings are `<samp><span class="samp">foo</span></samp>' and `<samp><span class="samp">bar</span></samp>', then if
  4927. two lines differ only in that `<samp><span class="samp">foo</span></samp>' in file 1 corresponds to
  4928. `<samp><span class="samp">bar</span></samp>' in file 2, the lines are treated as identical.
  4929.  
  4930.    <p>It is not clear how general this feature can or should be, or
  4931. what syntax should be used for it.
  4932.  
  4933.    <p>A partial substitute is to filter one or both files before comparing,
  4934. e.g.:
  4935.  
  4936. <pre class="example">     sed 's/foo/bar/g' file1 | diff - file2
  4937. </pre>
  4938.    <p>However, this outputs the filtered text, not the original.
  4939.  
  4940. <div class="node">
  4941. <p><hr>
  4942. <a name="Speedups"></a>
  4943. Previous: <a rel="previous" accesskey="p" href="#Ignoring-Changes">Ignoring Changes</a>,
  4944. Up: <a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>
  4945.  
  4946. </div>
  4947.  
  4948. <h4 class="subsection">18.1.7 Improving Performance</h4>
  4949.  
  4950. <p>When comparing two large directory structures, one of which was
  4951. originally copied from the other with time stamps preserved (e.g.,
  4952. with `<samp><span class="samp">cp -pR</span></samp>'), it would greatly improve performance if an option
  4953. told <samp><span class="command">diff</span></samp> to assume that two files with the same size and
  4954. time stamps have the same content.  See <a href="#diff-Performance">diff Performance</a>.
  4955.  
  4956. <div class="node">
  4957. <p><hr>
  4958. <a name="Bugs"></a>
  4959. Previous: <a rel="previous" accesskey="p" href="#Shortcomings">Shortcomings</a>,
  4960. Up: <a rel="up" accesskey="u" href="#Projects">Projects</a>
  4961.  
  4962. </div>
  4963.  
  4964. <h3 class="section">18.2 Reporting Bugs</h3>
  4965.  
  4966. <p><a name="index-bug-reports-168"></a><a name="index-reporting-bugs-169"></a>
  4967. If you think you have found a bug in <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>,
  4968. <samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp>, or <samp><span class="command">sdiff</span></samp>, please report it
  4969. by electronic mail to the
  4970. <a href="http://mail.gnu.org/mailman/listinfo/bug-gnu-utils">GNU utilities bug report mailing list</a> <a href="mailto:bug-gnu-utils@gnu.org">bug-gnu-utils@gnu.org</a>.  Please send
  4971. bug reports for <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> to
  4972. <a href="mailto:bug-patch@gnu.org">bug-patch@gnu.org</a>.  Send as precise a description of the
  4973. problem as you can, including the output of the <samp><span class="option">--version</span></samp>
  4974. option and sample input files that produce the bug, if applicable.  If
  4975. you have a nontrivial fix for the bug, please send it as well.  If you
  4976. have a patch, please send it too.  It may simplify the maintainer's
  4977. job if the patch is relative to a recent test release, which you can
  4978. find in the directory <a href="ftp://alpha.gnu.org/gnu/diffutils/">ftp://alpha.gnu.org/gnu/diffutils/</a>.
  4979.  
  4980. <div class="node">
  4981. <p><hr>
  4982. <a name="Copying-This-Manual"></a>
  4983. Next: <a rel="next" accesskey="n" href="#Index">Index</a>,
  4984. Previous: <a rel="previous" accesskey="p" href="#Projects">Projects</a>,
  4985. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  4986.  
  4987. </div>
  4988.  
  4989. <h2 class="appendix">Appendix A Copying This Manual</h2>
  4990.  
  4991. <ul class="menu">
  4992. <li><a accesskey="1" href="#GNU-Free-Documentation-License">GNU Free Documentation License</a>:   License for copying this manual. 
  4993. </ul>
  4994.  
  4995. <div class="node">
  4996. <p><hr>
  4997. <a name="GNU-Free-Documentation-License"></a>
  4998. Up: <a rel="up" accesskey="u" href="#Copying-This-Manual">Copying This Manual</a>
  4999.  
  5000. </div>
  5001.  
  5002. <h3 class="appendixsec">A.1 GNU Free Documentation License</h3>
  5003.  
  5004. <p><a name="index-FDL_002c-GNU-Free-Documentation-License-170"></a><div align="center">Version 1.1, March 2000</div>
  5005.  
  5006. <pre class="display">     Copyright © 2000 Free Software Foundation, Inc.
  5007.      59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
  5008.      
  5009.      Everyone is permitted to copy and distribute verbatim copies
  5010.      of this license document, but changing it is not allowed.
  5011. </pre>
  5012.      <ol type=1 start=0>
  5013. <li>PREAMBLE
  5014.  
  5015.      <p>The purpose of this License is to make a manual, textbook, or other
  5016. written document <dfn>free</dfn> in the sense of freedom: to assure everyone
  5017. the effective freedom to copy and redistribute it, with or without
  5018. modifying it, either commercially or noncommercially.  Secondarily,
  5019. this License preserves for the author and publisher a way to get
  5020. credit for their work, while not being considered responsible for
  5021. modifications made by others.
  5022.  
  5023.      <p>This License is a kind of “copyleft”, which means that derivative
  5024. works of the document must themselves be free in the same sense.  It
  5025. complements the GNU General Public License, which is a copyleft
  5026. license designed for free software.
  5027.  
  5028.      <p>We have designed this License in order to use it for manuals for free
  5029. software, because free software needs free documentation: a free
  5030. program should come with manuals providing the same freedoms that the
  5031. software does.  But this License is not limited to software manuals;
  5032. it can be used for any textual work, regardless of subject matter or
  5033. whether it is published as a printed book.  We recommend this License
  5034. principally for works whose purpose is instruction or reference.
  5035.  
  5036.      <li>APPLICABILITY AND DEFINITIONS
  5037.  
  5038.      <p>This License applies to any manual or other work that contains a
  5039. notice placed by the copyright holder saying it can be distributed
  5040. under the terms of this License.  The “Document”, below, refers to any
  5041. such manual or work.  Any member of the public is a licensee, and is
  5042. addressed as “you”.
  5043.  
  5044.      <p>A “Modified Version” of the Document means any work containing the
  5045. Document or a portion of it, either copied verbatim, or with
  5046. modifications and/or translated into another language.
  5047.  
  5048.      <p>A “Secondary Section” is a named appendix or a front-matter section of
  5049. the Document that deals exclusively with the relationship of the
  5050. publishers or authors of the Document to the Document's overall subject
  5051. (or to related matters) and contains nothing that could fall directly
  5052. within that overall subject.  (For example, if the Document is in part a
  5053. textbook of mathematics, a Secondary Section may not explain any
  5054. mathematics.)  The relationship could be a matter of historical
  5055. connection with the subject or with related matters, or of legal,
  5056. commercial, philosophical, ethical or political position regarding
  5057. them.
  5058.  
  5059.      <p>The “Invariant Sections” are certain Secondary Sections whose titles
  5060. are designated, as being those of Invariant Sections, in the notice
  5061. that says that the Document is released under this License.
  5062.  
  5063.      <p>The “Cover Texts” are certain short passages of text that are listed,
  5064. as Front-Cover Texts or Back-Cover Texts, in the notice that says that
  5065. the Document is released under this License.
  5066.  
  5067.      <p>A “Transparent” copy of the Document means a machine-readable copy,
  5068. represented in a format whose specification is available to the
  5069. general public, whose contents can be viewed and edited directly and
  5070. straightforwardly with generic text editors or (for images composed of
  5071. pixels) generic paint programs or (for drawings) some widely available
  5072. drawing editor, and that is suitable for input to text formatters or
  5073. for automatic translation to a variety of formats suitable for input
  5074. to text formatters.  A copy made in an otherwise Transparent file
  5075. format whose markup has been designed to thwart or discourage
  5076. subsequent modification by readers is not Transparent.  A copy that is
  5077. not “Transparent” is called “Opaque”.
  5078.  
  5079.      <p>Examples of suitable formats for Transparent copies include plain
  5080. <span class="sc">ascii</span> without markup, Texinfo input format, LaTeX input format,
  5081. <acronym>SGML</acronym> or <acronym>XML</acronym> using a publicly available
  5082. <acronym>DTD</acronym>, and standard-conforming simple <acronym>HTML</acronym> designed
  5083. for human modification.  Opaque formats include PostScript,
  5084. <acronym>PDF</acronym>, proprietary formats that can be read and edited only by
  5085. proprietary word processors, <acronym>SGML</acronym> or <acronym>XML</acronym> for which
  5086. the <acronym>DTD</acronym> and/or processing tools are not generally available,
  5087. and the machine-generated <acronym>HTML</acronym> produced by some word
  5088. processors for output purposes only.
  5089.  
  5090.      <p>The “Title Page” means, for a printed book, the title page itself,
  5091. plus such following pages as are needed to hold, legibly, the material
  5092. this License requires to appear in the title page.  For works in
  5093. formats which do not have any title page as such, “Title Page” means
  5094. the text near the most prominent appearance of the work's title,
  5095. preceding the beginning of the body of the text.
  5096.  
  5097.      <li>VERBATIM COPYING
  5098.  
  5099.      <p>You may copy and distribute the Document in any medium, either
  5100. commercially or noncommercially, provided that this License, the
  5101. copyright notices, and the license notice saying this License applies
  5102. to the Document are reproduced in all copies, and that you add no other
  5103. conditions whatsoever to those of this License.  You may not use
  5104. technical measures to obstruct or control the reading or further
  5105. copying of the copies you make or distribute.  However, you may accept
  5106. compensation in exchange for copies.  If you distribute a large enough
  5107. number of copies you must also follow the conditions in section 3.
  5108.  
  5109.      <p>You may also lend copies, under the same conditions stated above, and
  5110. you may publicly display copies.
  5111.  
  5112.      <li>COPYING IN QUANTITY
  5113.  
  5114.      <p>If you publish printed copies of the Document numbering more than 100,
  5115. and the Document's license notice requires Cover Texts, you must enclose
  5116. the copies in covers that carry, clearly and legibly, all these Cover
  5117. Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
  5118. the back cover.  Both covers must also clearly and legibly identify
  5119. you as the publisher of these copies.  The front cover must present
  5120. the full title with all words of the title equally prominent and
  5121. visible.  You may add other material on the covers in addition. 
  5122. Copying with changes limited to the covers, as long as they preserve
  5123. the title of the Document and satisfy these conditions, can be treated
  5124. as verbatim copying in other respects.
  5125.  
  5126.      <p>If the required texts for either cover are too voluminous to fit
  5127. legibly, you should put the first ones listed (as many as fit
  5128. reasonably) on the actual cover, and continue the rest onto adjacent
  5129. pages.
  5130.  
  5131.      <p>If you publish or distribute Opaque copies of the Document numbering
  5132. more than 100, you must either include a machine-readable Transparent
  5133. copy along with each Opaque copy, or state in or with each Opaque copy
  5134. a publicly-accessible computer-network location containing a complete
  5135. Transparent copy of the Document, free of added material, which the
  5136. general network-using public has access to download anonymously at no
  5137. charge using public-standard network protocols.  If you use the latter
  5138. option, you must take reasonably prudent steps, when you begin
  5139. distribution of Opaque copies in quantity, to ensure that this
  5140. Transparent copy will remain thus accessible at the stated location
  5141. until at least one year after the last time you distribute an Opaque
  5142. copy (directly or through your agents or retailers) of that edition to
  5143. the public.
  5144.  
  5145.      <p>It is requested, but not required, that you contact the authors of the
  5146. Document well before redistributing any large number of copies, to give
  5147. them a chance to provide you with an updated version of the Document.
  5148.  
  5149.      <li>MODIFICATIONS
  5150.  
  5151.      <p>You may copy and distribute a Modified Version of the Document under
  5152. the conditions of sections 2 and 3 above, provided that you release
  5153. the Modified Version under precisely this License, with the Modified
  5154. Version filling the role of the Document, thus licensing distribution
  5155. and modification of the Modified Version to whoever possesses a copy
  5156. of it.  In addition, you must do these things in the Modified Version:
  5157.  
  5158.           <ol type=A start=1>
  5159. <li>Use in the Title Page (and on the covers, if any) a title distinct
  5160. from that of the Document, and from those of previous versions
  5161. (which should, if there were any, be listed in the History section
  5162. of the Document).  You may use the same title as a previous version
  5163. if the original publisher of that version gives permission.
  5164.  
  5165.           <li>List on the Title Page, as authors, one or more persons or entities
  5166. responsible for authorship of the modifications in the Modified
  5167. Version, together with at least five of the principal authors of the
  5168. Document (all of its principal authors, if it has less than five).
  5169.  
  5170.           <li>State on the Title page the name of the publisher of the
  5171. Modified Version, as the publisher.
  5172.  
  5173.           <li>Preserve all the copyright notices of the Document.
  5174.  
  5175.           <li>Add an appropriate copyright notice for your modifications
  5176. adjacent to the other copyright notices.
  5177.  
  5178.           <li>Include, immediately after the copyright notices, a license notice
  5179. giving the public permission to use the Modified Version under the
  5180. terms of this License, in the form shown in the Addendum below.
  5181.  
  5182.           <li>Preserve in that license notice the full lists of Invariant Sections
  5183. and required Cover Texts given in the Document's license notice.
  5184.  
  5185.           <li>Include an unaltered copy of this License.
  5186.  
  5187.           <li>Preserve the section entitled “History”, and its title, and add to
  5188. it an item stating at least the title, year, new authors, and
  5189. publisher of the Modified Version as given on the Title Page.  If
  5190. there is no section entitled “History” in the Document, create one
  5191. stating the title, year, authors, and publisher of the Document as
  5192. given on its Title Page, then add an item describing the Modified
  5193. Version as stated in the previous sentence.
  5194.  
  5195.           <li>Preserve the network location, if any, given in the Document for
  5196. public access to a Transparent copy of the Document, and likewise
  5197. the network locations given in the Document for previous versions
  5198. it was based on.  These may be placed in the “History” section. 
  5199. You may omit a network location for a work that was published at
  5200. least four years before the Document itself, or if the original
  5201. publisher of the version it refers to gives permission.
  5202.  
  5203.           <li>In any section entitled “Acknowledgments” or “Dedications”,
  5204. preserve the section's title, and preserve in the section all the
  5205. substance and tone of each of the contributor acknowledgments
  5206. and/or dedications given therein.
  5207.  
  5208.           <li>Preserve all the Invariant Sections of the Document,
  5209. unaltered in their text and in their titles.  Section numbers
  5210. or the equivalent are not considered part of the section titles.
  5211.  
  5212.           <li>Delete any section entitled “Endorsements”.  Such a section
  5213. may not be included in the Modified Version.
  5214.  
  5215.           <li>Do not retitle any existing section as “Endorsements”
  5216. or to conflict in title with any Invariant Section.
  5217.           </ol>
  5218.  
  5219.      <p>If the Modified Version includes new front-matter sections or
  5220. appendices that qualify as Secondary Sections and contain no material
  5221. copied from the Document, you may at your option designate some or all
  5222. of these sections as invariant.  To do this, add their titles to the
  5223. list of Invariant Sections in the Modified Version's license notice. 
  5224. These titles must be distinct from any other section titles.
  5225.  
  5226.      <p>You may add a section entitled “Endorsements”, provided it contains
  5227. nothing but endorsements of your Modified Version by various
  5228. parties—for example, statements of peer review or that the text has
  5229. been approved by an organization as the authoritative definition of a
  5230. standard.
  5231.  
  5232.      <p>You may add a passage of up to five words as a Front-Cover Text, and a
  5233. passage of up to 25 words as a Back-Cover Text, to the end of the list
  5234. of Cover Texts in the Modified Version.  Only one passage of
  5235. Front-Cover Text and one of Back-Cover Text may be added by (or
  5236. through arrangements made by) any one entity.  If the Document already
  5237. includes a cover text for the same cover, previously added by you or
  5238. by arrangement made by the same entity you are acting on behalf of,
  5239. you may not add another; but you may replace the old one, on explicit
  5240. permission from the previous publisher that added the old one.
  5241.  
  5242.      <p>The author(s) and publisher(s) of the Document do not by this License
  5243. give permission to use their names for publicity for or to assert or
  5244. imply endorsement of any Modified Version.
  5245.  
  5246.      <li>COMBINING DOCUMENTS
  5247.  
  5248.      <p>You may combine the Document with other documents released under this
  5249. License, under the terms defined in section 4 above for modified
  5250. versions, provided that you include in the combination all of the
  5251. Invariant Sections of all of the original documents, unmodified, and
  5252. list them all as Invariant Sections of your combined work in its
  5253. license notice.
  5254.  
  5255.      <p>The combined work need only contain one copy of this License, and
  5256. multiple identical Invariant Sections may be replaced with a single
  5257. copy.  If there are multiple Invariant Sections with the same name but
  5258. different contents, make the title of each such section unique by
  5259. adding at the end of it, in parentheses, the name of the original
  5260. author or publisher of that section if known, or else a unique number. 
  5261. Make the same adjustment to the section titles in the list of
  5262. Invariant Sections in the license notice of the combined work.
  5263.  
  5264.      <p>In the combination, you must combine any sections entitled “History”
  5265. in the various original documents, forming one section entitled
  5266. “History”; likewise combine any sections entitled “Acknowledgments”,
  5267. and any sections entitled “Dedications”.  You must delete all sections
  5268. entitled “Endorsements.”
  5269.  
  5270.      <li>COLLECTIONS OF DOCUMENTS
  5271.  
  5272.      <p>You may make a collection consisting of the Document and other documents
  5273. released under this License, and replace the individual copies of this
  5274. License in the various documents with a single copy that is included in
  5275. the collection, provided that you follow the rules of this License for
  5276. verbatim copying of each of the documents in all other respects.
  5277.  
  5278.      <p>You may extract a single document from such a collection, and distribute
  5279. it individually under this License, provided you insert a copy of this
  5280. License into the extracted document, and follow this License in all
  5281. other respects regarding verbatim copying of that document.
  5282.  
  5283.      <li>AGGREGATION WITH INDEPENDENT WORKS
  5284.  
  5285.      <p>A compilation of the Document or its derivatives with other separate
  5286. and independent documents or works, in or on a volume of a storage or
  5287. distribution medium, does not as a whole count as a Modified Version
  5288. of the Document, provided no compilation copyright is claimed for the
  5289. compilation.  Such a compilation is called an “aggregate”, and this
  5290. License does not apply to the other self-contained works thus compiled
  5291. with the Document, on account of their being thus compiled, if they
  5292. are not themselves derivative works of the Document.
  5293.  
  5294.      <p>If the Cover Text requirement of section 3 is applicable to these
  5295. copies of the Document, then if the Document is less than one quarter
  5296. of the entire aggregate, the Document's Cover Texts may be placed on
  5297. covers that surround only the Document within the aggregate. 
  5298. Otherwise they must appear on covers around the whole aggregate.
  5299.  
  5300.      <li>TRANSLATION
  5301.  
  5302.      <p>Translation is considered a kind of modification, so you may
  5303. distribute translations of the Document under the terms of section 4. 
  5304. Replacing Invariant Sections with translations requires special
  5305. permission from their copyright holders, but you may include
  5306. translations of some or all Invariant Sections in addition to the
  5307. original versions of these Invariant Sections.  You may include a
  5308. translation of this License provided that you also include the
  5309. original English version of this License.  In case of a disagreement
  5310. between the translation and the original English version of this
  5311. License, the original English version will prevail.
  5312.  
  5313.      <li>TERMINATION
  5314.  
  5315.      <p>You may not copy, modify, sublicense, or distribute the Document except
  5316. as expressly provided for under this License.  Any other attempt to
  5317. copy, modify, sublicense or distribute the Document is void, and will
  5318. automatically terminate your rights under this License.  However,
  5319. parties who have received copies, or rights, from you under this
  5320. License will not have their licenses terminated so long as such
  5321. parties remain in full compliance.
  5322.  
  5323.      <li>FUTURE REVISIONS OF THIS LICENSE
  5324.  
  5325.      <p>The Free Software Foundation may publish new, revised versions
  5326. of the GNU Free Documentation License from time to time.  Such new
  5327. versions will be similar in spirit to the present version, but may
  5328. differ in detail to address new problems or concerns.  See
  5329. <a href="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</a>.
  5330.  
  5331.      <p>Each version of the License is given a distinguishing version number. 
  5332. If the Document specifies that a particular numbered version of this
  5333. License “or any later version” applies to it, you have the option of
  5334. following the terms and conditions either of that specified version or
  5335. of any later version that has been published (not as a draft) by the
  5336. Free Software Foundation.  If the Document does not specify a version
  5337. number of this License, you may choose any version ever published (not
  5338. as a draft) by the Free Software Foundation.
  5339.         </ol>
  5340.  
  5341. <h4 class="appendixsubsec">A.1.1 ADDENDUM: How to use this License for your documents</h4>
  5342.  
  5343. <p>To use this License in a document you have written, include a copy of
  5344. the License in the document and put the following copyright and
  5345. license notices just after the title page:
  5346.  
  5347. <pre class="smallexample">       Copyright (C)  <var>year</var>  <var>your name</var>.
  5348.        Permission is granted to copy, distribute and/or modify this document
  5349.        under the terms of the GNU Free Documentation License, Version 1.1
  5350.        or any later version published by the Free Software Foundation;
  5351.        with the Invariant Sections being <var>list their titles</var>, with the
  5352.        Front-Cover Texts being <var>list</var>, and with the Back-Cover Texts being <var>list</var>.
  5353.        A copy of the license is included in the section entitled ``GNU
  5354.        Free Documentation License''.
  5355. </pre>
  5356.    <p>If you have no Invariant Sections, write “with no Invariant Sections”
  5357. instead of saying which ones are invariant.  If you have no
  5358. Front-Cover Texts, write “no Front-Cover Texts” instead of
  5359. “Front-Cover Texts being <var>list</var>”; likewise for Back-Cover Texts.
  5360.  
  5361.    <p>If your document contains nontrivial examples of program code, we
  5362. recommend releasing these examples in parallel under your choice of
  5363. free software license, such as the GNU General Public License,
  5364. to permit their use in free software.
  5365.  
  5366. <!-- Local Variables: -->
  5367. <!-- ispell-local-pdict: "ispell-dict" -->
  5368. <!-- End: -->
  5369. <div class="node">
  5370. <p><hr>
  5371. <a name="Index"></a>
  5372. Previous: <a rel="previous" accesskey="p" href="#Copying-This-Manual">Copying This Manual</a>,
  5373. Up: <a rel="up" accesskey="u" href="#Top">Top</a>
  5374.  
  5375. </div>
  5376.  
  5377. <h2 class="appendix">Appendix B Index</h2>
  5378.  
  5379. <ul class="index-cp" compact>
  5380. <li><a href="#index-g_t_0040samp_007b_0021_007d-output-format-20">`<samp><span class="samp">!</span></samp>' output format</a>: <a href="#Context">Context</a></li>
  5381. <li><a href="#index-g_t_0040samp_007b_002b_002d_007d-output-format-24">`<samp><span class="samp">+-</span></samp>' output format</a>: <a href="#Unified-Format">Unified Format</a></li>
  5382. <li><a href="#index-g_t_0040samp_007b_003c_007d-output-format-18">`<samp><span class="samp"><</span></samp>' output format</a>: <a href="#Normal">Normal</a></li>
  5383. <li><a href="#index-g_t_0040samp_007b_003c_003c_003c_003c_003c_003c_003c_007d-for-marking-conflicts-70">`<samp><span class="samp"><<<<<<<</span></samp>' for marking conflicts</a>: <a href="#Marking-Conflicts">Marking Conflicts</a></li>
  5384. <li><a href="#index-g_t_005fPOSIX2_005fVERSION-161"><code>_POSIX2_VERSION</code></a>: <a href="#Standards-conformance">Standards conformance</a></li>
  5385. <li><a href="#index-aligning-tab-stops-55">aligning tab stops</a>: <a href="#Tabs">Tabs</a></li>
  5386. <li><a href="#index-alternate-file-names-32">alternate file names</a>: <a href="#Alternate-Names">Alternate Names</a></li>
  5387. <li><a href="#index-backup-file-names-104">backup file names</a>: <a href="#Backup-Names">Backup Names</a></li>
  5388. <li><a href="#index-backup-file-strategy-103">backup file strategy</a>: <a href="#Backups">Backups</a></li>
  5389. <li><a href="#index-binary-file-diff-11">binary file diff</a>: <a href="#Binary">Binary</a></li>
  5390. <li><a href="#index-blank-and-tab-difference-suppression-4">blank and tab difference suppression</a>: <a href="#White-Space">White Space</a></li>
  5391. <li><a href="#index-blank-line-difference-suppression-6">blank line difference suppression</a>: <a href="#Blank-Lines">Blank Lines</a></li>
  5392. <li><a href="#index-brief-difference-reports-10">brief difference reports</a>: <a href="#Brief">Brief</a></li>
  5393. <li><a href="#index-bug-reports-168">bug reports</a>: <a href="#Bugs">Bugs</a></li>
  5394. <li><a href="#index-C-function-headings-30">C function headings</a>: <a href="#C-Function-Headings">C Function Headings</a></li>
  5395. <li><a href="#index-C-if_002dthen_002delse-output-format-44">C if-then-else output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
  5396. <li><a href="#index-case-difference-suppression-7">case difference suppression</a>: <a href="#Case-Folding">Case Folding</a></li>
  5397. <li><a href="#index-ClearCase-84">ClearCase</a>: <a href="#Revision-Control">Revision Control</a></li>
  5398. <li><a href="#index-g_t_0040command_007bcmp_007d-invocation-126"><samp><span class="command">cmp</span></samp> invocation</a>: <a href="#Invoking-cmp">Invoking cmp</a></li>
  5399. <li><a href="#index-g_t_0040command_007bcmp_007d-options-127"><samp><span class="command">cmp</span></samp> options</a>: <a href="#cmp-Options">cmp Options</a></li>
  5400. <li><a href="#index-columnar-output-36">columnar output</a>: <a href="#Side-by-Side">Side by Side</a></li>
  5401. <li><a href="#index-common-mistakes-with-patches-122">common mistakes with patches</a>: <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a></li>
  5402. <li><a href="#index-comparing-three-files-58">comparing three files</a>: <a href="#Comparing-Three-Files">Comparing Three Files</a></li>
  5403. <li><a href="#index-conflict-65">conflict</a>: <a href="#diff3-Merging">diff3 Merging</a></li>
  5404. <li><a href="#index-conflict-marking-69">conflict marking</a>: <a href="#Marking-Conflicts">Marking Conflicts</a></li>
  5405. <li><a href="#index-context-output-format-19">context output format</a>: <a href="#Context">Context</a></li>
  5406. <li><a href="#index-creating-files-95">creating files</a>: <a href="#Creating-and-Removing">Creating and Removing</a></li>
  5407. <li><a href="#index-diagnostics-from-_0040command_007bpatch_007d-110">diagnostics from <samp><span class="command">patch</span></samp></a>: <a href="#patch-Messages">patch Messages</a></li>
  5408. <li><a href="#index-g_t_0040command_007bdiff_007d-invocation-144"><samp><span class="command">diff</span></samp> invocation</a>: <a href="#Invoking-diff">Invoking diff</a></li>
  5409. <li><a href="#index-diff-merging-74">diff merging</a>: <a href="#Interactive-Merging">Interactive Merging</a></li>
  5410. <li><a href="#index-g_t_0040command_007bdiff_007d-options-145"><samp><span class="command">diff</span></samp> options</a>: <a href="#diff-Options">diff Options</a></li>
  5411. <li><a href="#index-g_t_0040command_007bdiff_007d-sample-input-15"><samp><span class="command">diff</span></samp> sample input</a>: <a href="#Sample-diff-Input">Sample diff Input</a></li>
  5412. <li><a href="#index-g_t_0040command_007bdiff3_007d-hunks-63"><samp><span class="command">diff3</span></samp> hunks</a>: <a href="#diff3-Hunks">diff3 Hunks</a></li>
  5413. <li><a href="#index-g_t_0040command_007bdiff3_007d-invocation-148"><samp><span class="command">diff3</span></samp> invocation</a>: <a href="#Invoking-diff3">Invoking diff3</a></li>
  5414. <li><a href="#index-g_t_0040command_007bdiff3_007d-options-149"><samp><span class="command">diff3</span></samp> options</a>: <a href="#diff3-Options">diff3 Options</a></li>
  5415. <li><a href="#index-g_t_0040command_007bdiff3_007d-sample-input-60"><samp><span class="command">diff3</span></samp> sample input</a>: <a href="#Sample-diff3-Input">Sample diff3 Input</a></li>
  5416. <li><a href="#index-directories-and-patch-101">directories and patch</a>: <a href="#patch-Directories">patch Directories</a></li>
  5417. <li><a href="#index-directory-structure-changes-165">directory structure changes</a>: <a href="#Changing-Structure">Changing Structure</a></li>
  5418. <li><a href="#index-dry-runs-for-_0040command_007bpatch_007d-94">dry runs for <samp><span class="command">patch</span></samp></a>: <a href="#Dry-Runs">Dry Runs</a></li>
  5419. <li><a href="#index-g_t_0040command_007bed_007d-script-output-format-39"><samp><span class="command">ed</span></samp> script output format</a>: <a href="#ed-Scripts">ed Scripts</a></li>
  5420. <li><a href="#index-EDITOR-79"><code>EDITOR</code></a>: <a href="#Merge-Commands">Merge Commands</a></li>
  5421. <li><a href="#index-empty-files_002c-removing-96">empty files, removing</a>: <a href="#Creating-and-Removing">Creating and Removing</a></li>
  5422. <li><a href="#index-exabyte_002c-definition-of-139">exabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5423. <li><a href="#index-exbibyte_002c-definition-of-140">exbibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5424. <li><a href="#index-FDL_002c-GNU-Free-Documentation-License-170">FDL, GNU Free Documentation License</a>: <a href="#GNU-Free-Documentation-License">GNU Free Documentation License</a></li>
  5425. <li><a href="#index-file-name-alternates-33">file name alternates</a>: <a href="#Alternate-Names">Alternate Names</a></li>
  5426. <li><a href="#index-file-names-with-unusual-characters-167">file names with unusual characters</a>: <a href="#Unusual-File-Names">Unusual File Names</a></li>
  5427. <li><a href="#index-format-of-_0040command_007bdiff_007d-output-14">format of <samp><span class="command">diff</span></samp> output</a>: <a href="#Output-Formats">Output Formats</a></li>
  5428. <li><a href="#index-format-of-_0040command_007bdiff3_007d-output-59">format of <samp><span class="command">diff3</span></samp> output</a>: <a href="#Comparing-Three-Files">Comparing Three Files</a></li>
  5429. <li><a href="#index-formats-for-if_002dthen_002delse-line-groups-47">formats for if-then-else line groups</a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
  5430. <li><a href="#index-forward-_0040command_007bed_007d-script-output-format-40">forward <samp><span class="command">ed</span></samp> script output format</a>: <a href="#Forward-ed">Forward ed</a></li>
  5431. <li><a href="#index-full-lines-51">full lines</a>: <a href="#Incomplete-Lines">Incomplete Lines</a></li>
  5432. <li><a href="#index-function-headings_002c-C-31">function headings, C</a>: <a href="#C-Function-Headings">C Function Headings</a></li>
  5433. <li><a href="#index-fuzz-factor-when-patching-92">fuzz factor when patching</a>: <a href="#Inexact">Inexact</a></li>
  5434. <li><a href="#index-gibibyte_002c-definition-of-134">gibibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5435. <li><a href="#index-gigabyte_002c-definition-of-133">gigabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5436. <li><a href="#index-headings-26">headings</a>: <a href="#Sections">Sections</a></li>
  5437. <li><a href="#index-hunks-3">hunks</a>: <a href="#Hunks">Hunks</a></li>
  5438. <li><a href="#index-hunks-for-_0040command_007bdiff3_007d-62">hunks for <samp><span class="command">diff3</span></samp></a>: <a href="#diff3-Hunks">diff3 Hunks</a></li>
  5439. <li><a href="#index-if_002dthen_002delse-output-format-43">if-then-else output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
  5440. <li><a href="#index-g_t_0040command_007bifdef_007d-output-format-45"><samp><span class="command">ifdef</span></samp> output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
  5441. <li><a href="#index-imperfect-patch-application-88">imperfect patch application</a>: <a href="#Imperfect">Imperfect</a></li>
  5442. <li><a href="#index-incomplete-line-merging-72">incomplete line merging</a>: <a href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a></li>
  5443. <li><a href="#index-incomplete-lines-50">incomplete lines</a>: <a href="#Incomplete-Lines">Incomplete Lines</a></li>
  5444. <li><a href="#index-inexact-patches-91">inexact patches</a>: <a href="#Inexact">Inexact</a></li>
  5445. <li><a href="#index-inhibit-messages-from-_0040command_007bpatch_007d-113">inhibit messages from <samp><span class="command">patch</span></samp></a>: <a href="#More-or-Fewer-Messages">More or Fewer Messages</a></li>
  5446. <li><a href="#index-interactive-merging-75">interactive merging</a>: <a href="#Interactive-Merging">Interactive Merging</a></li>
  5447. <li><a href="#index-introduction-2">introduction</a>: <a href="#Comparison">Comparison</a></li>
  5448. <li><a href="#index-intuiting-file-names-from-patches-100">intuiting file names from patches</a>: <a href="#Multiple-Patches">Multiple Patches</a></li>
  5449. <li><a href="#index-invoking-_0040command_007bcmp_007d-125">invoking <samp><span class="command">cmp</span></samp></a>: <a href="#Invoking-cmp">Invoking cmp</a></li>
  5450. <li><a href="#index-invoking-_0040command_007bdiff_007d-143">invoking <samp><span class="command">diff</span></samp></a>: <a href="#Invoking-diff">Invoking diff</a></li>
  5451. <li><a href="#index-invoking-_0040command_007bdiff3_007d-147">invoking <samp><span class="command">diff3</span></samp></a>: <a href="#Invoking-diff3">Invoking diff3</a></li>
  5452. <li><a href="#index-invoking-_0040command_007bpatch_007d-151">invoking <samp><span class="command">patch</span></samp></a>: <a href="#Invoking-patch">Invoking patch</a></li>
  5453. <li><a href="#index-invoking-_0040command_007bsdiff_007d-155">invoking <samp><span class="command">sdiff</span></samp></a>: <a href="#Invoking-sdiff">Invoking sdiff</a></li>
  5454. <li><a href="#index-keyboard-input-to-_0040command_007bpatch_007d-114">keyboard input to <samp><span class="command">patch</span></samp></a>: <a href="#patch-and-Keyboard-Input">patch and Keyboard Input</a></li>
  5455. <li><a href="#index-kibibyte_002c-definition-of-130">kibibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5456. <li><a href="#index-kilobyte_002c-definition-of-129">kilobyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5457. <li><a href="#index-LC_005fCOLLATE-53"><code>LC_COLLATE</code></a>: <a href="#Comparing-Directories">Comparing Directories</a></li>
  5458. <li><a href="#index-LC_005fNUMERIC-48"><code>LC_NUMERIC</code></a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
  5459. <li><a href="#index-LC_005fTIME-21"><code>LC_TIME</code></a>: <a href="#Detailed-Context">Detailed Context</a></li>
  5460. <li><a href="#index-line-formats-49">line formats</a>: <a href="#Line-Formats">Line Formats</a></li>
  5461. <li><a href="#index-line-group-formats-46">line group formats</a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
  5462. <li><a href="#index-mebibyte_002c-definition-of-132">mebibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5463. <li><a href="#index-megabyte_002c-definition-of-131">megabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5464. <li><a href="#index-merge-commands-77">merge commands</a>: <a href="#Merge-Commands">Merge Commands</a></li>
  5465. <li><a href="#index-merged-_0040command_007bdiff3_007d-format-71">merged <samp><span class="command">diff3</span></samp> format</a>: <a href="#Bypassing-ed">Bypassing ed</a></li>
  5466. <li><a href="#index-merged-output-format-42">merged output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
  5467. <li><a href="#index-merging-from-a-common-ancestor-64">merging from a common ancestor</a>: <a href="#diff3-Merging">diff3 Merging</a></li>
  5468. <li><a href="#index-merging-interactively-78">merging interactively</a>: <a href="#Merge-Commands">Merge Commands</a></li>
  5469. <li><a href="#index-messages-from-_0040command_007bpatch_007d-111">messages from <samp><span class="command">patch</span></samp></a>: <a href="#patch-Messages">patch Messages</a></li>
  5470. <li><a href="#index-multibyte-characters-163">multibyte characters</a>: <a href="#Internationalization">Internationalization</a></li>
  5471. <li><a href="#index-multiple-patches-99">multiple patches</a>: <a href="#Multiple-Patches">Multiple Patches</a></li>
  5472. <li><a href="#index-newline-treatment-by-_0040command_007bdiff_007d-52">newline treatment by <samp><span class="command">diff</span></samp></a>: <a href="#Incomplete-Lines">Incomplete Lines</a></li>
  5473. <li><a href="#index-normal-output-format-17">normal output format</a>: <a href="#Normal">Normal</a></li>
  5474. <li><a href="#index-options-for-_0040command_007bcmp_007d-128">options for <samp><span class="command">cmp</span></samp></a>: <a href="#cmp-Options">cmp Options</a></li>
  5475. <li><a href="#index-options-for-_0040command_007bdiff_007d-146">options for <samp><span class="command">diff</span></samp></a>: <a href="#diff-Options">diff Options</a></li>
  5476. <li><a href="#index-options-for-_0040command_007bdiff3_007d-150">options for <samp><span class="command">diff3</span></samp></a>: <a href="#diff3-Options">diff3 Options</a></li>
  5477. <li><a href="#index-options-for-_0040command_007bpatch_007d-154">options for <samp><span class="command">patch</span></samp></a>: <a href="#patch-Options">patch Options</a></li>
  5478. <li><a href="#index-options-for-_0040command_007bsdiff_007d-158">options for <samp><span class="command">sdiff</span></samp></a>: <a href="#sdiff-Options">sdiff Options</a></li>
  5479. <li><a href="#index-output-formats-13">output formats</a>: <a href="#Output-Formats">Output Formats</a></li>
  5480. <li><a href="#index-overlap-66">overlap</a>: <a href="#diff3-Merging">diff3 Merging</a></li>
  5481. <li><a href="#index-overlapping-change_002c-selection-of-67">overlapping change, selection of</a>: <a href="#Which-Changes">Which Changes</a></li>
  5482. <li><a href="#index-overview-of-_0040command_007bdiff_007d-and-_0040command_007bpatch_007d-1">overview of <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></a>: <a href="#Overview">Overview</a></li>
  5483. <li><a href="#index-paginating-_0040command_007bdiff_007d-output-56">paginating <samp><span class="command">diff</span></samp> output</a>: <a href="#Pagination">Pagination</a></li>
  5484. <li><a href="#index-patch-consumer-tips-121">patch consumer tips</a>: <a href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a></li>
  5485. <li><a href="#index-g_t_0040command_007bpatch_007d-input-format-80"><samp><span class="command">patch</span></samp> input format</a>: <a href="#patch-Input">patch Input</a></li>
  5486. <li><a href="#index-g_t_0040command_007bpatch_007d-invocation-152"><samp><span class="command">patch</span></samp> invocation</a>: <a href="#Invoking-patch">Invoking patch</a></li>
  5487. <li><a href="#index-g_t_0040command_007bpatch_007d-messages-and-questions-109"><samp><span class="command">patch</span></samp> messages and questions</a>: <a href="#patch-Messages">patch Messages</a></li>
  5488. <li><a href="#index-g_t_0040command_007bpatch_007d-options-153"><samp><span class="command">patch</span></samp> options</a>: <a href="#patch-Options">patch Options</a></li>
  5489. <li><a href="#index-patch-producer-tips-120">patch producer tips</a>: <a href="#Tips-for-Patch-Producers">Tips for Patch Producers</a></li>
  5490. <li><a href="#index-patch_002c-common-mistakes-123">patch, common mistakes</a>: <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a></li>
  5491. <li><a href="#index-PATCH_005fGET-86"><code>PATCH_GET</code></a>: <a href="#Revision-Control">Revision Control</a></li>
  5492. <li><a href="#index-PATCH_005fVERSION_005fCONTROL-106"><code>PATCH_VERSION_CONTROL</code></a>: <a href="#Backup-Names">Backup Names</a></li>
  5493. <li><a href="#index-patches_002c-shrinking-124">patches, shrinking</a>: <a href="#Generating-Smaller-Patches">Generating Smaller Patches</a></li>
  5494. <li><a href="#index-patching-directories-102">patching directories</a>: <a href="#patch-Directories">patch Directories</a></li>
  5495. <li><a href="#index-pebibyte_002c-definition-of-138">pebibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5496. <li><a href="#index-performance-of-_0040command_007bdiff_007d-57">performance of <samp><span class="command">diff</span></samp></a>: <a href="#diff-Performance">diff Performance</a></li>
  5497. <li><a href="#index-petabyte_002c-definition-of-137">petabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5498. <li><a href="#index-g_t_0040sc_007bposix_007d-159"><span class="sc">posix</span></a>: <a href="#Standards-conformance">Standards conformance</a></li>
  5499. <li><a href="#index-g_t_0040sc_007bposix_007d-117"><span class="sc">posix</span></a>: <a href="#patch-and-POSIX">patch and POSIX</a></li>
  5500. <li><a href="#index-POSIXLY_005fCORRECT-160"><code>POSIXLY_CORRECT</code></a>: <a href="#Standards-conformance">Standards conformance</a></li>
  5501. <li><a href="#index-POSIXLY_005fCORRECT-118"><code>POSIXLY_CORRECT</code></a>: <a href="#patch-and-POSIX">patch and POSIX</a></li>
  5502. <li><a href="#index-projects-for-directories-162">projects for directories</a>: <a href="#Shortcomings">Shortcomings</a></li>
  5503. <li><a href="#index-quoting-style-115">quoting style</a>: <a href="#patch-Quoting-Style">patch Quoting Style</a></li>
  5504. <li><a href="#index-QUOTING_005fSTYLE-116"><code>QUOTING_STYLE</code></a>: <a href="#patch-Quoting-Style">patch Quoting Style</a></li>
  5505. <li><a href="#index-g_t_0040sc_007brcs_007d-83"><span class="sc">rcs</span></a>: <a href="#Revision-Control">Revision Control</a></li>
  5506. <li><a href="#index-g_t_0040sc_007brcs_007d-script-output-format-41"><span class="sc">rcs</span> script output format</a>: <a href="#RCS">RCS</a></li>
  5507. <li><a href="#index-regular-expression-matching-headings-29">regular expression matching headings</a>: <a href="#Specified-Headings">Specified Headings</a></li>
  5508. <li><a href="#index-regular-expression-suppression-8">regular expression suppression</a>: <a href="#Specified-Folding">Specified Folding</a></li>
  5509. <li><a href="#index-reject-file-names-108">reject file names</a>: <a href="#Reject-Names">Reject Names</a></li>
  5510. <li><a href="#index-removing-empty-files-97">removing empty files</a>: <a href="#Creating-and-Removing">Creating and Removing</a></li>
  5511. <li><a href="#index-reporting-bugs-169">reporting bugs</a>: <a href="#Bugs">Bugs</a></li>
  5512. <li><a href="#index-reversed-patches-90">reversed patches</a>: <a href="#Reversed-Patches">Reversed Patches</a></li>
  5513. <li><a href="#index-revision-control-81">revision control</a>: <a href="#Revision-Control">Revision Control</a></li>
  5514. <li><a href="#index-sample-input-for-_0040command_007bdiff_007d-16">sample input for <samp><span class="command">diff</span></samp></a>: <a href="#Sample-diff-Input">Sample diff Input</a></li>
  5515. <li><a href="#index-sample-input-for-_0040command_007bdiff3_007d-61">sample input for <samp><span class="command">diff3</span></samp></a>: <a href="#Sample-diff3-Input">Sample diff3 Input</a></li>
  5516. <li><a href="#index-g_t_0040sc_007bsccs_007d-85"><span class="sc">sccs</span></a>: <a href="#Revision-Control">Revision Control</a></li>
  5517. <li><a href="#index-script-output-formats-38">script output formats</a>: <a href="#Scripts">Scripts</a></li>
  5518. <li><a href="#index-g_t_0040command_007bsdiff_007d-invocation-156"><samp><span class="command">sdiff</span></samp> invocation</a>: <a href="#Invoking-sdiff">Invoking sdiff</a></li>
  5519. <li><a href="#index-g_t_0040command_007bsdiff_007d-options-157"><samp><span class="command">sdiff</span></samp> options</a>: <a href="#sdiff-Options">sdiff Options</a></li>
  5520. <li><a href="#index-g_t_0040command_007bsdiff_007d-output-format-76"><samp><span class="command">sdiff</span></samp> output format</a>: <a href="#sdiff-Option-Summary">sdiff Option Summary</a></li>
  5521. <li><a href="#index-section-headings-27">section headings</a>: <a href="#Sections">Sections</a></li>
  5522. <li><a href="#index-side-by-side-34">side by side</a>: <a href="#Side-by-Side">Side by Side</a></li>
  5523. <li><a href="#index-side-by-side-format-37">side by side format</a>: <a href="#Side-by-Side-Format">Side by Side Format</a></li>
  5524. <li><a href="#index-SIMPLE_005fBACKUP_005fSUFFIX-105"><code>SIMPLE_BACKUP_SUFFIX</code></a>: <a href="#Backup-Names">Backup Names</a></li>
  5525. <li><a href="#index-special-files-166">special files</a>: <a href="#Special-Files">Special Files</a></li>
  5526. <li><a href="#index-specified-headings-28">specified headings</a>: <a href="#Specified-Headings">Specified Headings</a></li>
  5527. <li><a href="#index-summarizing-which-files-differ-9">summarizing which files differ</a>: <a href="#Brief">Brief</a></li>
  5528. <li><a href="#index-System-V-_0040command_007bdiff3_007d-compatibility-73">System V <samp><span class="command">diff3</span></samp> compatibility</a>: <a href="#Saving-the-Changed-File">Saving the Changed File</a></li>
  5529. <li><a href="#index-tab-and-blank-difference-suppression-5">tab and blank difference suppression</a>: <a href="#White-Space">White Space</a></li>
  5530. <li><a href="#index-tab-stop-alignment-54">tab stop alignment</a>: <a href="#Tabs">Tabs</a></li>
  5531. <li><a href="#index-tebibyte_002c-definition-of-136">tebibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5532. <li><a href="#index-terabyte_002c-definition-of-135">terabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5533. <li><a href="#index-testing-_0040command_007bpatch_007d-93">testing <samp><span class="command">patch</span></samp></a>: <a href="#Dry-Runs">Dry Runs</a></li>
  5534. <li><a href="#index-text-versus-binary-diff-12">text versus binary diff</a>: <a href="#Binary">Binary</a></li>
  5535. <li><a href="#index-time-stamp-format_002c-context-diffs-22">time stamp format, context diffs</a>: <a href="#Detailed-Context">Detailed Context</a></li>
  5536. <li><a href="#index-time-stamp-format_002c-unified-diffs-25">time stamp format, unified diffs</a>: <a href="#Detailed-Unified">Detailed Unified</a></li>
  5537. <li><a href="#index-time-stamps-on-patched-files-98">time stamps on patched files</a>: <a href="#Patching-Time-Stamps">Patching Time Stamps</a></li>
  5538. <li><a href="#index-traditional-_0040command_007bpatch_007d-119">traditional <samp><span class="command">patch</span></samp></a>: <a href="#patch-and-Tradition">patch and Tradition</a></li>
  5539. <li><a href="#index-two_002dcolumn-output-35">two-column output</a>: <a href="#Side-by-Side">Side by Side</a></li>
  5540. <li><a href="#index-unified-output-format-23">unified output format</a>: <a href="#Unified-Format">Unified Format</a></li>
  5541. <li><a href="#index-unmerged-change-68">unmerged change</a>: <a href="#Which-Changes">Which Changes</a></li>
  5542. <li><a href="#index-varying_002dwidth-characters-164">varying-width characters</a>: <a href="#Internationalization">Internationalization</a></li>
  5543. <li><a href="#index-verbose-messages-from-_0040command_007bpatch_007d-112">verbose messages from <samp><span class="command">patch</span></samp></a>: <a href="#More-or-Fewer-Messages">More or Fewer Messages</a></li>
  5544. <li><a href="#index-version-control-82">version control</a>: <a href="#Revision-Control">Revision Control</a></li>
  5545. <li><a href="#index-VERSION_005fCONTROL-107"><code>VERSION_CONTROL</code></a>: <a href="#Backup-Names">Backup Names</a></li>
  5546. <li><a href="#index-VERSION_005fCONTROL-87"><code>VERSION_CONTROL</code></a>: <a href="#Revision-Control">Revision Control</a></li>
  5547. <li><a href="#index-white-space-in-patches-89">white space in patches</a>: <a href="#Changed-White-Space">Changed White Space</a></li>
  5548. <li><a href="#index-yottabyte_002c-definition-of-142">yottabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5549. <li><a href="#index-zettabyte_002c-definition-of-141">zettabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
  5550.    </ul><div class="footnote">
  5551. <hr>
  5552. <a name="texinfo-footnotes-in-document"></a><h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> A coding error in <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> version
  5553. 2.5.4 causes it to always use `<samp><span class="samp">~</span></samp>', but this should be fixed in
  5554. the next release.</p>
  5555.  
  5556.    <p><hr></div>
  5557.  
  5558. </body></html>
  5559.  
  5560.